Doug Bryant

Tech thoughts and notes

Moving From Subversion to Git

I just finished moving all our repositories from subversion to git.  There is lots of documentation on the web, but none of it ties everything together.  Specifically, once you get your subversion repository including all branches and tags imported into a local copy of git, how do you push your git repository including all branches and tags to a remote git server?   This was important to us because we have ongoing work in some branches which are not ready to be pushed to trunk yet.

I started out by following the excellent instructions at to setup our own git repository.  Follow these instructions and create a simple git repository with only a couple of files to make sure it works and become familiar with it.  At this point, you have a working central git repository but you are not yet ready to import your subversion repository.  If using github, you can skip this step.

Next, go grab git2svn from github.  This will download an entire subversion project, including branches and tags, into a local git repository.  Depending on the size of your codebase and number of branches/tags, etc, this may take a while.  Our smaller projects took about 10 minutes.  Our larger project took almost an hour.  It differs from git-svn in that it converts anything in subversion tags to actual git tags.

Now for the magic of pushing your local git repository imported from subversion to the central git repository your team will use.   At this point, you should have a working central/remote git repository you are going to use.

Inside the root of your local git project, run these commands, replacing everything which is in caps. git remote add origin git@YOUR_SERVER_HOSTNAME:YOUR_PROJECT_NAME.git git push origin master:refs/heads/master

After this runs, you have only pushed the trunk to the remote repository (now called master).  You will also want to push all your tags and branches.  With git, you have to explicitly push your tags.

git push --tags

And now for the branches.  This was the only piece I could not find on the interweb.  This is achieved by the command

git push --all

The --all command per the documentation specifies that all refs under $GIT_DIR/refs/heads/ be pushed rather than naming each ref to push.

That should be all there is to it. Our other developers were able to clone the newly minted git repository and start developing where they left off on their branch with the command:

git clone git@YOUR_SERVER_HOSTNAME:YOUR_PROJECT_NAME.git git checkout -b local_branch_name --track origin/remote_branch_name