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.

hg-fast-export: convert Mercurial repositories to git repositories

There are *-to-git conversion tools for converting almost every SCM repository to a git repository.

I used hg quite extensively earlier this year, but switched to git within the last couple months.  This is partly because I’ve found that git is much faster (on linux) and because it’s easier for me to wrap my mind around the the git philosophy of branching vs. hg’s.  I had to dig up an old mercurial repository from an old project today and was decided to convert it to git.

Here’s what I had to do:

$ git clone git://repo.or.cz/fast-export.git
$ mkdir new_git_repo
$ cd new_git_repo
$ git init
$ /path/to/hg-fast-export.sh -r /path/to/hg_repo
$ git checkout HEAD

A couple notes:

  1. I had to run hg-fast-export.sh instead of hg-fast-import.sh, contrary to what the README said.  Typo?
  2. It doesn’t check out a working copy for you (it’s a feature, not a bug 🙂 ), so I had to do it myself in the last step.
  3. I found that hg-fast-export works better than hg-to-git.  I had some problems converting very large hg repositories.  Maybe it’s preformance-related as hg-fast-export uses the Mercurial and git python libs directly while hg-to-git uses some combination of shell and python.

October 16, 2008. Tags: , . Uncategorized. 6 comments.