Sean’s Obsessions

Sean Walberg’s blog

Fun With Git

I’ve started using Git instead of svn. Like many other people, I tried it out to get easier branching, but found it’s just a pleasure to use in general.

One great feature is that git can work with an SVN repository. You use git to check out some SVN code into a local git repository, you work with the repo as if it were git, then you commit your changes back to svn.

The lowdown on this is:

1
2
3
4
5
6
7
8
9
# Check out the svn repo
# It may take a while because it's copying all the changes, not just a checkout
git svn init http://myrepo/myproject/trunk myproject
cd myproject
# do some work
# commit to git
git commit -a -m "did some work"
# send updates to svn
git svn dcommit

But wait, someone else has done some work and you want to pull the latest changes from svn to your git repo

1
git svn rebase

Nice eh? So let’s say you’re working in your git repo, and want to branch

1
2
git branch somefeature
git checkout somefeature

You’re working along, and you want to pull changes from svn into master and your branch.

1
2
3
4
5
6
git checkout master
git svn rebase
# master is up to date
# so merge master into the branch
git checkout somefeature
git merge master

This is so easy to use! Previously, with SVN, I’d branch, work on the feature, and then merge back to trunk. Given how painful merges were, there was no hope that I’d be merging trunk changes into my feature branch.

I’m sure my tune will change the first time I blow up my repository though :)

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.