SVN + Git = Awesome
February 20th, 2008
I’ve been a big fan of SVN for several years now. I even helped my former employer migrate from VSS a couple of years ago after I sold everybody on the idea. I have lots of love for SVN, but it has its limitations, especially the need to have network connectivity to a central repository. I know at least some people would love to have a way to still commit code when offline. So, here’s how I did it with SVN and Git.
Git is a DVCS that works differently than SVN. Instead of making changes in your working copy and submitting them to a central repository, your working copy is your repository. You can push changes to another repository or you can pull changes from another repository. It’s a nice way of working, and it’s what they use on the Linux kernel. The Git folks have a nice tutorial for SVN users.
The key feature of Git that makes it well suited for use alongside SVN is that it keeps all of its metadata in one folder at the top of your repository. It does not put one in each directory like SVN does. So you can make your SVN working copy into a Git repository and then ignore the folder and SVN knows nothing about it. Here’s what you do.
At the top level of your SVN working copy:
$ git init $ echo .svn > .gitignore $ git add * $ git add .gitignore $ git commit -m "Initial commit"
Now we just need to teach SVN to ignore the Git stuff. So open up your ~/.subversion/config file and find the [miscellany] section. You should see a commented out setting for global-ignores. Uncomment it and add .git* to it like this:
[miscellany] ### Set global-ignores to a set of whitespace-delimited globs ### which Subversion will ignore in its ’status’ output, and ### while importing or adding files and directories. global-ignores = *.o *.lo *.la \#*\# .*.rej *.rej .*~ *~ .\#* .DS_Store .git*
And voila! When you’re able to connect to your SVN repo, you can use SVN. But when you’re offline and still want the ability to use version control to incrementally save your changes, you can use Git. They’re working on the same files, so they play together very nicely.
February 22nd, 2008 at 10:22 am
[...] 22nd, 2008 Yesterday I wrote about using SVN and Git together to have version control away from the network your SVN server is on. Now, I’ll [...]
March 8th, 2008 at 7:49 pm
[...] 8th, 2008 I’ve really fallen head over heels in love with Git. But my original solution was really a hack. There is a better way to [...]
May 3rd, 2008 at 4:57 pm
I think using the git-svn command is a better alternative than let ignore each VCS ignore the other VCS’s files. With git-svn, you only need .git and there’s no need to have a copy of each checked out file in your .svn directory.
May 3rd, 2008 at 5:19 pm
Bram:
That is very true. If you look at the second trackback on this post, you’ll notice that I started using git-svn about a week later.