Subversion branches with Git and SourceTree

Where I work we use Subversion for source control.  I really like Git, and I use the git-svn functionality so I use git locally against a shared subversion server.

I am also using a Mac and prefer SourceTree as a frontend for my source control.  It handles the git-svn stuff automatically and very nicely.

The problem I have is that we use a nonstandard branching organization in subversion, but I want to be able to switch between different subversion branches inside of my local git repository.  I couldn’t figure out how to do this for the longest time, and finally ran into a post somewhere that gave me enough of a hint to figure out how to make it work.  It’s not pretty, and I may be doing some unnecessary bits, but it does seem to work.  Here’s how I do it:

  1. Checkout the trunk subversion repository (using SourceTree) as a git repository.
  2. Open the configuration file at .git/config.
  3. Add a new remote section like this:
    [svn-remote "1.0svn"]
       url = https://my.svn.server/svn/branches/1.0/myproject/
       fetch = :refs/remotes/git-svn-1.0
    
  4. On a command line, in the local git repo, run
    git svn fetch 1.0svn
    
  5. Refresh the view in SourceTree. You will now see git-svn-1.0 listed as a remote under Subversion. You can check out the remote branch as a local branch that tracks the remote branch.
Advertisements

One thought on “Subversion branches with Git and SourceTree

  1. Your post got me going too. Have trying with SourceTree, TortoiseGit etc. Achieved a very simple solution by the end.


    git svn init http://yubico-openid-server.googlecode.com/svn/trunk/
    git svn fetch svn

    The init automatically created:

    [svn-remote "svn"]
    url = http://yubico-openid-server.googlecode.com/svn/trunk
    fetch = :refs/remotes/git-svn

    And now everyone is happy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s