Monday, May 05, 2008

Migrating from subversion to git

Last week I moved my project at work from subversion to git. I know you can use git-svn, but I needed some branching and history rewriting that I couldn't get to work with the way git-svn rewrites your commits. It may have been a solution looking for a problem, but oh well, because since I have switched, I've been able to do some amazing things in cleaning up my history and code branches.

If you haven't used git-svn here are the two posts that helped me most:
If you want a more full-fledged git hosting setup, you can use gitosis:

I already had my subversion tree checked out via git, but it was up-to-date and because each git-svn checkout creates it's own set of revisions to represent the repository, I just started from scratch. Also, HTTP doesn't seem useful as a central repository for an in-house group like mine because you're going to be pushing back to the repository, so didn't even bother setting it up. I know you can setup push over HTTP, but I heard working over ssh is faster. By the way, make sure you're using 1.5 or higher, anything less just doesn't cut it.
  1. I created a directory called /var/git and did a git-svn checkout of the subversion repository from the same server in there:
    1. mkdir myproj
    2. cd myproj
    3. git svn init -s file:///path/to/repo
  2. Then I created the public git repository: (from the Git user manual)
    1. cd ../
    2. git clone --bare myproj myproj.git
    3. cd myproj.git
    4. git --bare update-server-info
    5. chmod a+x hooks/post-update
Now you can clone your repository with ssh://, the ssh:// prefix isn't strictly neccesary, but it I like it.

You'll need to make sure you have public key ssh authentication setup for everyone using git. We already did so I didn't have to go through that. Also, if you don't trust your developers on the server, you can use set their shell to 'git-shell' which is a restricted shell that only allows git commands.

1 comment:

nothingmuch said...

In case you still care, git's grafts feature would have probably done what you needed.

I've posted on this in the context of git-svn based conversions, and David Wheeler has an interesting example from his Bricolage conversion.