rabejens rabejens - 1 month ago 13
Git Question

Wrong(?) branch prefixes migrating SVN to Git

I basically followed this howto to migrate an old, very big SVN repository to git. This does not work as expected. Here is an example excerpt from my checkout living in

~/git/old_svn_repo
(done with
git svn
but without
--no-metadata
):

remotes/origin/trunk
remotes/origin/branchX
remotes/origin/branchY # and many more


Next step is step 4, which seemed to work flawlessly. I pushed to the bare repository (note I used
~/git/new-bare.git
instead of
~/new-bare.git
):

git init --bare ~/git/new-bare.git
cd ~/git/new-bare.git
git symbolic-ref HEAD refs/heads/trunk
cd ~/git/old_svn_repo
git remote add bare ~/git/new-bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare


This got me a lot of output like

* [new branch] origin/trunk -> origin/trunk
* [new branch] origin/foo-> origin/foo
* [new branch] origin/bar-> origin/bar


Next is step 5 where you are supposed to rename
trunk
to
master
:

cd ~/git/new-bare.git
git branch -m trunk master


Here the problem starts:

I enter:

git branch -m trunk master


I get:

error: refname refs/heads/trunk not found
fatal: Branch rename failed


Doing
git branch -a
reveals that all branches are prefixed with
origin/
.

What did I do incorrectly here and how do I get that right?

Answer

After digging through SO some more, I found this question, and the answer by Pieter Breed. So I tried it, from the directory I cloned the SVN repository into:

cd ~/git/old_svn_repo
git remote add new_gitlab_server ssh://git@mygitlab.example.com/foo/bar.git
git push new_gitlab-server +refs/remotes/origin/*:refs/heads/*

and poof, everything appeared on my Gitlab as expected without the intermediate step creating a local bare repo.

Now, "master" is still called "trunk" which is OK, but leads to warning: remote HEAD refers to nonexistent ref, unable to checkout. on the first clone, so I did the following:

git clone ssh://git@mygitlab.example.com/foo/bar.git
cd bar
git checkout trunk
git checkout -b master
git push -u origin master

It seems the tags were converted to branches, but we can live with that.

Comments