Moving from Subversion to Git & GitHub
Although Git has been making the rounds in social media for a while, it really caught my attention this year at RailsConf with Scott Chacon’s presentation; Getting Git.
After RailsConf and throughout the summer, I was determined to learn more about the fledgling revision control system but something always came up to squash that effort.
Luckily, Planet Argon uses Git exclusively for their version control system and it’s allowed me to learn some of the basics via my favorite learning technique; trial by fire.
In the few weeks that I have been working with Git I’ve been very impressed with how easy it is to get up and running. I’ve been so impressed that I decided to migrate away from Subversion and move to using Git and GitHub for all of my big projects (including this blogging engine).
WARNING: By following these instructions you are taking responsibility for what happens on your system. As with anything, your mileage may vary and I suggest you do a complete backup of your client machine and server machines.
First this is first; install Git. If you’re on a Debian Linux based machine you can install the Git package by running the following commands:
sudo aptitude install git-core git-svn
If you’re on a Mac, I suggest using MacPorts to install the software by running the following commands (after MacPorts has been installed)
sudo port install git-core git-svn
If you’re using a different OS, consult the Git install documentation.
Before I continue further, it’s important to understand my goal. I want to migrate everything from Subversion to Git and then dump Subversion. I do not want to keep Subversion at the end of this process. There are ways to bridge Git to Subversion just in case you can’t completely remove Subversion from your infrastructure but that’s not my intent.
With that in mind, if you have any uncommitted files from your Subversion repository, I suggest finishing up your work and getting all files committed before proceeding otherwise they won’t be available for Git.
First thing you’ll want to do is to identify yourself to Git so that when you make commits, it’ll know who you are. This is done by the following command (this can also be done on a per project basis but I’m doing it globally):
git config --global user.email your_email_here.com
Once that is finished, we’ll use git-svn to “clone” our Subversion repository. Basically, this checks out your entire project into a branch titled git-svn and then creates a new branch called master. Finally it merges git-svn to your master branch.
The command to run this “cloning” process is:
git svn clone path_to_your_subversion_respository_here
You may need to include “/trunk” to the end of your Subversion repository. Also, depending on the size of your project, the cloning process could take a while.
I’m paranoid, so I like to confirm that both the git-svn and the master branches are merged together at the end of the “cloning” process. First, make sure that you are in the master branch by running the following command:
git checkout master
Then merge git-svn into it by running:
git merge git-svn
You should be greeted with a message that reads “Already up to date.” Everything should now be in Git and you could theoretically be able to dump Subversion now. Obviously, a pragmatic approach would be to archive your Subversion repository on a backup device just in case anything bad happens.
I should note that Git is now running on your local machine and you can make commits to your local repository. This is obviously different from the Subversion client-server model and if this makes you uncomfortable you can certainly setup an origin server to push and pull content from. I chose GitHub primarily because it’s easy to use and setup. Once you are signed up with GitHub, create a repository and run the following commands:
cd existing_git_repository git remote add origin github_repository_address git push origin master
I should make a footnote here. Since my Subversion repository isn’t available on the Internet, I wasn’t able to use GitHub’s Subversion import feature. Feel free to use that feature if your Subversion repository is available on the Internet. That way you can skip the whole git-svn thing.
At this point, feel free to delete the git-svn branch as it won’t be needed anymore. You can do this by running the following command:
git branch -d branch_name
Now that you have installed Git, what now?
I would suggest reading the article Git for Designers
More resources: