I have checked out a svn repository using git svn. Now I need to checkout one of the branches and track it. Which is the best way to do it?
1 Answers
Standard Subversion layout
Create a git clone of that includes your Subversion trunk, tags, and branches with
git svn clone http://svn.example.com/project -T trunk -b branches -t tags
The --stdlayout
option is a nice shortcut if your Subversion repository uses the typical structure:
git svn clone http://svn.example.com/project --stdlayout
Make your git repository ignore everything the subversion repo does:
git svn show-ignore >> .git/info/exclude
You should now be able to see all the Subversion branches on the git side:
git branch -r
Say the name of the branch in Subversion is waldo
. On the git side, you'd run
git checkout -b waldo-svn remotes/waldo
The -svn suffix is to avoid warnings of the form
warning: refname 'waldo' is ambiguous.
To update the git branch waldo-svn
, run
git checkout waldo-svn git svn rebase
Starting from a trunk-only checkout
To add a Subversion branch to a trunk-only clone, modify your git repository's .git/config
to contain
[svn-remote "svn-mybranch"] url = http://svn.example.com/project/branches/mybranch fetch = :refs/remotes/mybranch
You'll need to develop the habit of running
git svn fetch --fetch-all
to update all of what git svn
thinks are separate remotes. At this point, you can create and track branches as above. For example, to create a git branch that corresponds to mybranch, run
git checkout -b mybranch-svn remotes/mybranch
For the branches from which you intend to git svn dcommit
, keep their histories linear!
Further information
You may also be interested in reading an answer to a related question.

- 1
- 1

- 134,834
- 32
- 188
- 245
-
This doesn't work for me, as I have checked out the trunk using git svn clone.. I didn't set branches to be checked out... I think I need to to that firstly. – markovuksanovic Jul 13 '10 at 18:47
-
The fact is that I used git svn clone http://svn.example.com/project/trunk And now I don't know how to set other branches to be tracked without loosing my current repo... – markovuksanovic Jul 14 '10 at 16:17
-
22I would suggest providing a prefix for your svn remotes. (add `--prefix=svn/` when doing `git-svn init` or `git-svn clone`) This will eliminate the need to add a suffix on your local branches. – jasonkarns Jun 13 '11 at 17:07
-
If you have several branches don't forget to do "git checkout master" before taking care of an other branche – Heetola Sep 27 '12 at 17:45
-
If the `show-ignore` errors out, try `git svn show-ignore -i trunk` – Antti Haapala -- Слава Україні Aug 10 '14 at 12:49
-
Also note that even if you use the `--prefix=svn/`, so that your remote branch is called `remotes/svn/my-branch`, the shorter `git checkout -b my-branch` variant will not be able to automatically find & use the remote branch. It's probably due to that `git svn` doesn't write any `[remote "
"]` etc. into the `.git/config` file. – Petr Bodnár Feb 08 '20 at 14:48 -
What should be used in place of `http://svn.example.com/project` if the repository is stored on an NFS share, e.g. at `\\MyServer\Share\Project`? – Niko O Sep 21 '21 at 07:40