Git delete branch local only11/20/2023 Run a command for each item in the listīy the way the demo video goes into more detail and shows running these commands.Easily allow being able to do a dry run without really deleting the branches.Skip deleting the currently checked out branch even if it’s not in the whitelist because this could be a current work in progress branch that you will make a PR out of later.Whitelist 1 or more branches that will never get deleted such as main, master, production or whatever branch names you’ve chosen to be long running branches.List all of the branches in this git repo.The reason it’s not the end game solution is because we can turn it into a more general alias later (which we will).īefore we write any code, let’s whip up a little bit of pseudo code of how it’ll work: This won’t be our end game solution but it will work. To your surprise (or maybe not surprise) you might have dozens or even hundreds of old or unused branches.Ĭreating a 1 Liner to Clean Up Old Local Branches If you executed the above bullet points and locally ran git checkout main & git pull you would get the latest merged in changes but your local PR branch is still lingering around. In the end your remote repo doesn’t build up any branch cruft because chances are you configured your remote git service of choice to delete the PR branch after it’s been merged. ![]() Someone reviews that work and merges that PR into your main branch.You push that branch up and make a PR from it on GitHub, GitLab, Bitbucket, etc.You make a new local branch to do your work ( git checkout -b feature/something-cool). ![]() The use case around this is, let’s say you have a project you’re working on and: If you prefer video, I recorded a demo video on YouTube going over what’s written below with a number of examples. Quick Jump: Creating a 1 Liner to Clean Up Old Local Branches | Making It Easier to Use with a Function Alias | Demo Video Here's a 1 liner you can turn into an alias. Updated on November 15th, 2022 in #linux Delete Old or Unused Local Git Branches Using grep and xargs I like cleaning up unused branches and doing it manually can be tedious.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |