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