This question already has an answer here:
- How do I migrate an SVN repository with history to a new Git repository? 32 answers
I migrated our SVN repository to Git and pushed it to a central repository. We had a fair amount of tags and branches, but somehow we were not able to list and fetch those from a Git client. This was weird, because the tags and branches seemed to be available on the server.
With help from a Jon Maddox blog post, a blog post from Marc Liyanage and a SO answer from Casey I was able to stitch a solution together. Thanks for all the help!
Here's what I ended up doing. First I created a file with the svn committers:
local$ svn log svn://server/opt/svn/our_app |grep ^r[0-9] | cut -f2 -d\| |sort |uniq | tee ~/users.txt
alice
bob
eve
local$ vim ~/users.txt
local$ cat ~/users.txt
alice = Alice Malice <alice@malice.doh>
bob = Bob Hope <bob@hope.doh>
eve = Eve Leave <eve@leave.doh>
Then I created a git repo from our svn repo:
local$ mkdir our_app
local$ cd our_app
local$ git svn init --stdlayout svn://server/opt/svn/our_app
local$ git config svn.authorsfile ~/users.txt
local$ git svn fetch
local$ git svn create-ignore
local$ git commit -m 'added .gitignore, created from svn:ignore'
local$ for remote in `git branch -r`; do git checkout -b $remote $remote; done
This last step was crucial, since otherwise branches/tags were not available when cloning from a remote repository. Anyway, I pushed this to a new remote repo:
local$ ssh server
server$ mkdir /opt/git/our_app.git
server$ cd /opt/git/our_app.git
server$ git --bare init
server$ git config core.sharedrepository 1
server$ git config receive.denyNonFastforwards true
server$ find objects -type d -exec chmod 02770 {} \;
server$ exit
local$ git remote add origin ssh://server/opt/git/our_app.git
local$ git push --mirror
A fresh clone of the remote repository showed that everything was available:
local$ git clone ssh://server/opt/git/our_app.git
local$ cd our_app
local$ git branch -a
* master
remotes/origin/master
remotes/origin/pre-svn-move
remotes/origin/tags/mytag-0.1
remotes/origin/tags/mytag-0.2
remotes/origin/trunk
remotes/origin/mybranch-1
remotes/origin/mybranch-2
Now a remote branch could be checked out:
local$ git checkout -t origin/mybranch-1
local$ git branch
master
* mybranch-1
Just to re-iterate: this guide includes hints for remote tag and branch availability, mirroring to a remote repo and re-use of values in svn:ignore. I hadn't found all of these in one guide earlier.
A final note: ebneter's tip about svn2git was also great, since this one actually preserves tags as tags, while git-svn converts them to branches. On the other hand, I couldn't get "git svn create-ignore" to work with svn2git...