Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Checkout only certain branches with git-svn
If you want to clone an svn repository with git-svn but don't want it to push all the existing branches, here's what you should do.
* Clone with git-svn using the -T parameter to define your trunk path inside the svnrepo, at the same time instructing it to clone only the trunk:
git svn clone -T trunk
* If instead of cloning trunk you just want to clone a certain branch, do the same thing but change the path given to -T:
git svn clone -T branches/somefeature
This way, git svn will think that branch is the trunk and generate the following config on your .git/config file:
[svn-remote "svn"]
url =
fetch = PROJECT/branches/somefeature:refs/remotes/trunk
* If at any point after this you want to checkout additional branches, you first need to add it on your configuration file:
[svn-remote "svn"]
url =
fetch = PROJECT/branches/somefeature:refs/remotes/trunk
branches = PROJECT/branches/{anotherfeature}:refs/remotes/*
The branches config always needs a glob. In this case, we're just specifying just one branch but we could specify more, comma separating them, or all with a *.
* After this, issue the following command:
git svn fetch
Sit back. It's gonna take a while, and on large repos it might even fail. Sometimes just hitting CTRL+C and starting over solves it. Some dark magic here.
* After this, if you issue a git branch -r you can see your remote branch definitions:
git branch -r
* Now you can add a local branch which tracks the remote svn branch:
git branch --track myanotherfeature remotes/anotherfeature
Try not to use the same branch name for the local one if you don't wanna mess it up easily.

Thanks so much for this. Exactly what I've been seeking for days.

If you have branches with numbers in your repository after fetching you can safely delete them:

If you have complex paths that git-svn cannot understand then you can use this format instead in your .git/config file:
[svn-remote "svn"]
url =
fetch = trunk:refs/remotes/prod
fetch = branches/dev:refs/remotes/branches/dev
fetch = branches/features/feature 1:refs/remotes/branches/feature_1

Thank you for this trick, it saved me from looooong exporting of the whole project

skyezju commented May 8, 2015

Thank you! It helps me so much!

liuanyou commented Aug 6, 2015

This is cool, Thank you, very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment