This content originally appeared on DEV Community and was authored by Juan Belieni
Sometimes, deleting branches that we are no longer working on can be tedious. For this, you can create an alias to do the hard work for you.
All git aliases are located at the ~/.gitconfig
file:
...
[alias]
cm = commit # Example alias
The custom alias we will create will delete all branches except master and the current one:
git branch | grep -v "master" | grep -v "^*" | xargs git branch -d
At ~/.gitconfig
:
...
[alias]
del-branches = !git branch | grep -v "master" | grep -v "^*" | xargs git branch -d
If you want to add more branches than just the master, you can place them like this:
"master\|develop"
Finally, you just have to call the alias at your repository directory as a normal git command:
git del-branches
This content originally appeared on DEV Community and was authored by Juan Belieni
Juan Belieni | Sciencx (2021-08-30T14:30:39+00:00) Creating an alias for deleting useless git branches. Retrieved from https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.