As we’re migrating away from Subversion to Git, I’m having to learn a
lot about git-svn. Andy has posted a few
articles on this
topic, but I wanted to share a quick tip that I find myself forgetting.
Working with Subversion branches
While you’re hopefully already familiar with how great local branches are with Git, you might not know that you can connect local branches to remote branches in your Subversion repository. This allows those of us who are using Git locally to work against Subversion branches.
I’m going to assume the following:
- Your team is using Subversion
- Your team already has a branch that you’re working in
- Your team is following Subversion directory conventions
(
branches/,tags/, andtrunk/) - You have Git installed (with SVN extensions)
Checkout the Subversion project with Git
Please visit Andy’s tutorial, Git SVN Workflow, for a more detailed explanation of the following commands.
First, we’ll initialize your new local Git repository with git-svn.
git svn init -s http://svn.yourdomain.com/repos/project_name
Now, you’ll change directories to your new Git repository.
cd project_name
Let’s fetch all previous revisions into your local repository[^1^](#fn1){#fnref1 .footnote-ref role=”doc-noteref”}.
git svn fetch
Great, once this is done… you’re master (local) branch is linked
to trunk/.
Mapping a local repository to a remote branch
Assuming that your team is working in a Subversion branch on the current iteration of work. Our team has a naming convention for branches for each iteration. For example, if we’re in Iteration 18, we’ll write this as ITER-018 everywhere (Basecamp, Lighthouse, Subversion, etc…). At the start of each iteration, we create a new branch with this naming convention.
For ITER-018, the Subversion branch would be located at:
- http://svn.yourdomain.com/repos/project_name/branches/ITER-018
If you were to do a git branch -r, you should see ITER-018 show up
in the list. Now, the one thing that wasn’t clear when I first read the
git-svn documentation was that you can’t just checkout that branch
with one command. In fact, this has tripped me up a few times.
First, you’ll need to checkout a new local branch. I’ve opted to come
up with my own convention for local branches and in this case, I’ll
name it iter_018.
git co -b iter_018
So, now I’m in the iter_018 branch, which is local. I’m currently still
mapped to trunk/, which isn’t what we want. However, all we need to do
is reset where Git is currently pointed to. We can run git
reset to point
this to the ITER-018 branch.
git reset --hard ITER-018
That’s it! Now, the local iter_018 branch will point to
branches/ITER-018 in your Subversion repository. This will allow you
to work with your existing repository branch and still reap the benefits
of local Git repositories.
What about master?
Good question. The git reset command that you ran will ONLY apply that
that individual local branch. So, master is still pointing to
trunk/. This will allow you to have several local branches that map to
remote branches.
Next Steps…
If you’re working with Git already.. great!
If you’re working in an environment that using Subversion, git svn
provides you the ability to start exploring Git without making your
entire team switchover. Perhaps your a consultant and working for a
client that uses Subversion… no problem!
We’re still using Subversion for past client projects and are considering GitHub, which just launched (to the public) today for future projects. A few of us are already using GitHub for open source projects.
Fun.. I just saw the following tweet pass by as I began to wrap up this post.
::: thumbnail

[Uploaded with plasq’s
Skitch!]{style=”font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080”}
:::
The Gateway Drug… Git reminds me of Cake
Questions?
I know that I glossed over a few things, so feel free to post questions and/or tips for others who are looking to dabble with Git.
- ::: {#fn1} You’ll likely have problems if you don’t have a Git authors file specified in your git config.↩︎{.footnote-back role=”doc-backlink”} :::