Creating an alias for deleting useless git branches

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 c…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Creating an alias for deleting useless git branches." Juan Belieni | Sciencx - Monday August 30, 2021, https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/
HARVARD
Juan Belieni | Sciencx Monday August 30, 2021 » Creating an alias for deleting useless git branches., viewed ,<https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/>
VANCOUVER
Juan Belieni | Sciencx - » Creating an alias for deleting useless git branches. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/
CHICAGO
" » Creating an alias for deleting useless git branches." Juan Belieni | Sciencx - Accessed . https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/
IEEE
" » Creating an alias for deleting useless git branches." Juan Belieni | Sciencx [Online]. Available: https://www.scien.cx/2021/08/30/creating-an-alias-for-deleting-useless-git-branches/. [Accessed: ]
rf:citation
» Creating an alias for deleting useless git branches | Juan Belieni | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.