How to create a local git clone of a mercurial repo?

Harvey Chapman hchapman-hg at 3gfp.com
Tue Dec 16 16:12:55 UTC 2014


I’ve used the hggit extension with remote git repositories with no real issues, but I often want to create a local git clone of a throw-away mercurial repo to give to git-only developers. I’ve tried mimicking the process I use when creating new remote repositories, but I always get an error "abort: git remote error: refs/heads/master failed to update”. Am I doing something wrong? Is there a faster and/or better method?

$ hg init test.hg
$ cd test.hg/
$ touch file
$ hg commit -Am initial
adding file
$ hg bookmarks -r tip master
$ hg update master
$ echo -e "[paths]\ndefault = ../test.git" > .hg/hgrc
$ git init ../test.git
Initialized empty Git repository in /Users/hchapman/test.git/.git/
$ hg pull
pulling from /Users/hchapman/test.git
$ hg push
pushing to /Users/hchapman/test.git
searching for changes
adding objects
abort: git remote error: refs/heads/master failed to update
$

[time elapses] I guess I just needed to explain it to the duck. After typing the above text, I remembered that git updates working copies when you push. Adding “—bare” to the “git init” command above allows the process to succeed.

My other question still stands though. Is there a better way? I don’t really need to update the paths in my local hgrc, but usually when I make these repos, my intent is to keep pushing my changes to them.

Thanks,
Harvey


More information about the Mercurial mailing list