GitHub Tips: Removing a Remote Branch

If you are working on a branch and want to abandon it, what do you do?

It’s easy to remove it from your local repository:

$ git branch -d mybranch # delete branch "mybranch"

And then how do you remove it from a GitHub repository? This works:


$ git push git@github.com:<my_account>/<my_repository>.git :heads/<mybranch>

But there’s an easier way. Scott Chacon suggests:

You can also do (assuming ‘origin’ is the name of your remote):

git push origin :mybranch

Scott Chacon is the author of the Git Internals book from Peepcode.

One Response to “GitHub Tips: Removing a Remote Branch”

  1. Scott Chacon Says:

    You can also do (assuming ‘origin’ is the name of your remote) :

    git push origin :mybranch

    Which is the same syntax as pushing a branch ref there, except with a leading ‘:’ on the branch name – it just looks more complex to put the whole repo url there instead of your remote name, and the ‘heads/’ prefix shouldn’t be necessary.

Leave a Reply