Git Pushes New Branch With Master Content

- 1 answer

I migrate a repo from mercurial to git through:

git init gitrepo
cd gitrepo
hg_fastexport -r <../hgclone>

(I hope I didn´t forget anything) Then I created in GitLab an repository and in the gitrepo (to where hg-fastexport exported the sources) I created branches and pushed them like

git checkout -b v4.1
git push origin refs/heads/v4.1:refs/heads/v4.1

While this was working with 2 branches, it showed also up in Gitab, the last branch always gets the content of the master branch, not the v4.1 branch.



I found the error i´ve made. Maybe the problem was not so clear, but when i created a new branch the branch would had always the content of the master. It would contain not the branch. The reason for that was that i´ve forget, after i migrated from mercury to git, to check out the HEAD. It seems as if then i was working either on the master or a branch but while i forgot to checkout the (newly migrated HEAD), the content of the new branch and the master remained the same.

I will give here a receipt which led to a correct repository.

clone the Mercurial directory:

  • hg clone ./hgclone

Init the git directory:

  • git init git-dir
  • cd git-dir

  • migrate mercurial to git: hg-fast-export -r ../hgclone

  • git checkout HEAD
  • Add git repository: git remote add origin $remoterepo
  • Add current dir: git add .
  • commit: git commit -m "Initial Commit"
  • push: git push -u origin master

List the branches for to create and update them to the remote git-directory - git branch

checkout and add the branches to the remote git directory:

  • git checkout branch
  • git add .
  • git push origin refs/heads/branch:refs/heads/branch

This are the fundamental steps which worked for me for exporting a mercurial repository to git and store them with the right branches to the remote git repository.