How To Track A Subversion Branch In A Git Repository

The Problem:

For whatever reason, your project is using Subversion for version control and you're using Git to do your work. You need to track a branch from Subversion in your Git repository.

The Solutions:

I searched around for the solution to this problem and found many a circuitous web page describing how to do this. Here's your simple, step-by-step way of solving this problem.

Step 1: Add The Subversion Branch To Your Git Config

Edit $REPO/.git/config, adding the following:

  [svn-remote "svn-thebranch"]
          url = http://svn.yourrepository.com/yourproject/branches/thebranch/
          fetch = :refs/remotes/thebranch

Where thebranch is the name of the branch you're wanting to track.

Step 2: Update The Subversion Data

To do this, run:

  git svn fetch --fetch-all

and go get a drink. Or three, depending on how much data the Subversion repository is carrying. For my project this takes about 10-15 minutes easily.

Step 3: Check Out The Subversion Branch Locally

Simply type:

  git checkout -b thebranch remotes/thebranch

Now you've got a local instance which is not tracking the branch in Subversion. You should now be sitting in a local copy of the branch.

Step 4: Push The Branch To Your Git Repository

Now push this branch up to your Git repository with:

  git push origin HEAD:my-copy-of-thebranch [--set-upstream]

If you include the --set-upstream argument then your local branch will be setup to track changes to the branch you've just created remotely.

That's it!

Comments