gitmercurialversion-control-migration

Convert hg branches to git branches?


I must convert a branchy mercurial repo into a git repo AND continue to pull changes from mercurial to git (one-way only) for some time. Existing hg-to-git answers do not seem to handle branches correctly. For example, a small hg repo with 'default' and 'br1' branches results in this:

$ hg branches
br1                            3:a8914879f6bb
default                        2:4e6221bce113

cd ..
git-hg clone file:/path/to/hgrepo gitrepo

...<snip>
From .git/hgremote
 * [new branch]      br1        -> hg/br1
 * [new branch]      master     -> hg/master
From .git/hgremote
 * branch            master     -> FETCH_HEAD

cd gitrepo
git branch --list
* master

Git thinks there is only one branch 'master'. How can I make my mercurial branches to show up as identically named git branches? I can live with 'master' instead of 'default', but I must have all my other named branches in git.


Solution

  • The branches are imported as remote branches that means they are relative to the remote repository which happens to be a hg repository. If you type git branch -a you will be able to see all branches.

    You can create local branches of those remote branches simply like this:

    git branch <localname> <remotename>
    

    For example:

    git branch br1 hg/br1