git: Remove remote branch


git: Remove remote branch

Posted by Luis Majano
Mar 29, 2011 21:29:20 UTC
This is something I want to blog in order to save it for posterity so I don’t go crazy looking for this. I have a remote branch I committed but I need to remove it for whatever reason, how do I do this with git?

You do this in two easy steps:
  1. Remove the local branch either through your favorite GUI or via: git branch -d “branch name”
  2. Push the removed branch to the remote origin: git push origin :refs/heads/”branch name”

The key here is that you push a non-existent branch, so it basically removes it from the remote repository. That’s it!

Russ Johnson

You can shortcut the command on line 2 by simply typing:

git push origin :branchname

Not a huge deal but the less I can type on the commandline the better...

Konstantin

No, it is not always true:

$ git push origin :enable-some-locales error: unable to push to unqualified destination: enable-some-locales The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to '******' $ git push origin :refs/heads/enable-some-locales

  • [deleted] enable-some-locales