Recently I’ve been playing with git and I found it fascinating!, for those that still don’t know what it is, git is a really fast distributed revision control system (wikipedia). Now the problem is how to switch from subversion to git, fortunately git-svn helps a lot and we can play with git and subversion in many ways. Let’s talk about them from the easiest to the not-so-easy way. I’m supposing here that you want to move from a centralized subversion to a git repository that probably will be online on a server.

Complete migration from subversion to git

This is for those that want to throw subversion away completely, for some reason this is the easiest way to switch. First what you would do on the server:

# first clone the repository from subversion
# if you can use file:// it will be faster,
# otherwise use
[server]$ git svn clone -s file:///home/pplux/.../svn/MySuperProject tmp
# clone to a bare new git repository (with no track of subversion)
[server]$ git clone --bare file://`pwd`/tmp MySuperProject
# remove the old git repo from subversion, no longer needed
[server]$ rm -rf tmp/
# update server info, for "dumb" servers this is needed
[server]$ cd MySuperProject/
[server]$ git --bare update-server-info

Now clients can simple clone your repository and start working:
# use this for normal-read-only, or maybe you could use ssh://
# if you plan to upload data.

[client] $ git clone

Mirroring the subversion repository and keep subversion

Here we want to keep the subversion repository like the main reference of the project, but let people (or ourselves) use git for development. The reason to mirror the subversion is just a matter of speed, it is much faster to clone an existing git repository than cloning from subversion each time.

Here we will need to do a bit more of work, but it’s a much smoother way to migrate from subversion to git. First what we need to do on the server:

# Create and initialize a bare git repository
[server]$ mkdir MySuperProject[server]$ cd MySuperProject/
[server]$ git --bare init
Initialized empty Git repository in /home/pplux/.../MySuperProject/

# set svn project to import
[server]$ git --bare svn init -s

# fetch svn data (sloooow)
[server]$ git --bare svn fetch --all
A src/CMakeLists.txt
A CMakeLists.txt
W: +empty_dir: trunk/include

# auxiliary files to help "dumb" servers
[server]$ git --bare update-server-info

Now the client, here we will do much more work than before to setup both the origin from the git mirror and the subversion config to commit there future changes.

# Create and initialize our copy of the git repository
[client] $ mkdir MySuperProject
[client] $ cd MySuperProject/
[client] $ git init
Initialized empty Git repository in /Users/pplux/projects/MySuperProject/.git/

# setup the server as the initial origin of data
[client] $ git remote add origin

# also tell git to fecth data from the remote origin(that case svn)
[client] $ git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*'

# fetch data from the git mirror(takes a bit)
[client] $ git fetch
got 2c68737541f19685f667f601a502447425d1fcfe
walk 2c68737541f19685f667f601a502447425d1fcfe
got d4916373650b9bb636c0284dd501e6c7bfa8e304
got 13af9568120f8e7771bd386d9b7dadf69f1181cb

# setup the original subversion as
[client] $ git svn -s init

# rebuild data...
[client] $ git svn fetch
Rebuilding .git/svn/trunk/.rev_map.1a3bf6a2-ba3d-0410-9263-a3f888f14dcd ...
r1 = 126490373bfbc2a770d762398b67fffeef73bead
r2 = a2288725c8c68ef426b97cf2b28a9135a34734d3
r3 = 4158b92a5c68489bb6ff2b4f4567cf8f830d7282

# to start working create a master that will track "trunk"
[client] $ git checkout -b master -t trunk

Reasons for switching to git

The post ends here you can safely stop reading now, but if you ask me, there are some good reasons to switch to git:

  • it’s faster, not only faster when doing actual SCM work, it allows you to develop faster, no need to wait while the commit is transmitted to the server, you can work offline wherever you are…
  • it works well with subversion, you can use it even if the main project never moves from a subversion repository or you are the only one using git while everybody else is using subversion
  • you don’t need to develop a full feature before a commit, you can work on your own doing commits often without worrying about anybody else.
  • git is meant to work on branches, this is a different approach from the normal subversion use, with git you are supposed to work on branches, and it’s great! I like to develop different «features» on different branches, I can switch the branch, do several things at the same time… and so on.
  • you have the whole history, not just the last commit.
  • it’s secure, you don’t need several people to share the same repository, git «default» model works in a different way where each person has its own public git. But, everything in git is hashed, even branches, so you can easily check if your private git has the same things as the remote git (that’s difficult to achieve with subversion)
  • it’s like vim vs notepad! I like git because is fun, it can do many many things, and it’s always good to have something new to play with.
  • if CVS was for dinosaurs when you started using SVN, now SVN is for the Neanderthals… so start using git!
  • You don’t have to be a ruby developer to use git! git is another SCM… not the cool tool just for cool ruby developers… come on.
  • Because Linus Torvalds made it:
  • … well, maybe Linus is not a good reason to use it… I don’t fancy calling people ugly and idiot, anyway git is great.

And big thanks to slack for pointing me out git, if he says something is good stuff… believe him 🙂

Other good links about what we’ve talked here: