git-svn: fetch history from git clone

On there is a very useful trick:

If you want to be able to commit changes to the Subversion repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track the Subversion repository. To do that, inform git-svn of the location of the WebKit SVN repository, and update the branch that git-svn uses to track the Subversion repository so that it will re-use the history that we’ve already cloned from rather than trying to fetch it all from Subversion:

cd WebKit
git svn init --prefix=origin/ -T trunk
git config --replace svn-remote.svn.fetch trunk:refs/remotes/origin/master

This will add the following section to your .git/config:

[svn-remote "svn"]
url =
fetch = trunk:refs/remotes/origin/master

You can then run the following command to have git-svn rebuild its metadata from your local repository, and to pull any recent commits from the WebKit SVN repository.

git svn fetch

So, let’s say you have a subversion repository:


and you also have a git clone of that repository:


(Obviously these examples come from OpenWrt)
Now if you don’t want to fetch the whole history from svn, which will take forever, here is what you can do:

mkdir openwrt;cd openwrt;
git svn init --prefix=svn/ svn://
git remote add git://
git fetch
git config --replace svn-remote.svn.fetch trunk:refs/remotes/
git svn fetch
  1. The git config line tells git-svn to use the history in, so you won’t need to checkout the same commits from svn.
  2. Use --prefix=svn/ to separate upstream and svn upstream.

One thought on “git-svn: fetch history from git clone

  1. P.S. One shortcoming of this is that my ‘master’ branch is not following the upstream trunk. Instead, it points to the first branch under remotes/svn/. That’s because ‘trunk’ does not have its own item under remotes/svn anymore. It points to remotes/ instead.

Leave a Reply

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

You are commenting using your 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