This is the command I run when I want to delete a branch named chore/fix-typo from the default remote (which is named origin): git push origin --delete chore/fix-typo
Making My Life Easier
Typically when I want to delete a remote branch, I want to delete the branch on the remote named origin with the same name as the local branch I’m currently on. To make my life easier I’ve setup a Git alias to do this when I type git drb, for “d(elete) r(emote) b(ranch)”.
You can add this alias by running the following from the command line:
git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)'
After running the above command git drb will work for you and if you look in your Git config (~/.gitconfig), you’ll see a section that looks like
[alias]
drb = !git push origin --delete $(git rev-parse --abbrev-ref HEAD)
An Example
For example, if I’m on the branch chore/fix-typo, I want to delete the branch on the remote origin named chore/fix-typo.
In this situation, running git drb will behave the same as running git push origin --delete chore/fix-typo
How this Alias Works
The alias runs git push origin --delete followed by the current branch name (see Git Get Current Branch Name for more information on how this works).
Leave a Reply