How to delete a remote branch from a git repository

This isn’t obvious, so I thought I’d post an example for deleting a remote branch.

Let’s say you want to delete origin/some_branch from origin

$ git branch -a
* master
origin/master
origin/some_branch

To remove the branch, just do this:

$ git push origin :some_branch

Now, it’s gone!

$ git branch -a
* master
origin/master

From the git push manual page:

The canonical format of a <refspec> parameter is +?<src>:<dst>; that is, an optional plus +, followed by the source ref, followed by a colon :, followed by the destination ref.

Pushing an empty <src> allows you to delete the <dst> ref from the remote repository.

So, when you do “git push repo src:dest”, that translates to “git push <repository> <refspec>”.  In the example above, <repository> was “origin” and <refspec> was “:some_branch”.  Since there was no <src> part of the refspec, the <dst> ref was deleted from the remote repository.

Advertisements

October 24, 2008. Tags: . Uncategorized.

Leave a Comment

Be the first to comment!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback URI

%d bloggers like this: