How to delete a remote branch in git?

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In git, to delete a remote branch the syntax is …

git push [remotename] :[branch]

As an example …

git push origin :bugfix

would delete the branch named “bugfix” from the remote named “origin”.

This is assuming that you typically would delete the branch first locally with …

git branch -d bugfix

Remember the colon in deleting the remote branch

It is kind of difficult to remember with the colon there.   Remember that ..

git push origin bugfix

would create a new branch on the remote.  With the colon…

git push origin :bugfix

would delete the branch on the remote.

Another way to remember

In git, there is a local repository and a remote repository.  To update the remote with the local the generalized syntax is …

git push [remotename] [localbranch]:[remotebranch]

If we omit the [localbranch], then it deletes the [remotebranch] seeing that you had just pushed null to the remotebranch.