Last Updated: February 25, 2016
· ruzz311

Add an SVN remote to your Git repo

I love git. Who doesn't? I'll tell you who: larger companies with an existing infastructure that revolves around SVN. Luckily you can still reap some of the git-benefits by adding svn-remote branches!

You can clone an entire SVN repo (trunk, branches, tags):

$ git svn clone -T trunk -b branches -t tags

But sometimes we're in a hurry and only grab the trunk. What now? With the help of Ian Boston, I learned how to add remotes / branches after I've initialized my git-svn repo.

Adding Branches to an existing git-svn repo

  1. Edit the .git/config to add an svn-remote:

         repositoryformatversion = 0  
         filemode = true  
         bare = false  
         logallrefupdates = true  
       [svn-remote "svn"]  
         url =  
         fetch = :refs/remotes/git-svn 
       [svn-remote "svn2"]  
         url =  
         fetch = :refs/remotes/git-svn-mybranch
  2. Fetch the branch via terminal. "-r" followed immediately by a valid revision number will only fetch from that revision, but is optional. Say we wanted to fetch starting at revision 311 - So far so good? Don't believe me? Well fine, you can check to see if it worked by listing the branches.

    $ git svn fetch svn2 -r311  
    $ git branch -a
  3. Create/Switch branches

    $ git checkout git-svn-mybranch  
    $ git checkout -b master-mybranch