Search code examples
gitgit-svngit-clonegit-remote

Is there a way to clone a git repository including its remote repositories?


Is there a way to use some git clone / fetch mechanism to keep the repo in my clone up to date including all refs/remotes/ from the remote?

This has nothing to do with git fetch --all, git pull --all or git svn. It's just about copying the remotes of a remote to a clone.

A command like this would be great:

git clone --include-remote-remotes git@linuxmachine:TheGitSvnClone

And then periodically

git fetch --update-remote-remotes origin

Some Details:

The remote has its own remote named svn which contains some branches:

  • refs/heads/master
  • refs/remotes/svn/trunk
  • refs/remotes/svn/branch1
  • refs/remotes/svn/branch2

As a result of the clone I'd expect a normal git repository including a working copy (checked out files) and the following refs:

  • refs/heads/master
  • (refs/remotes/origin/master)
  • refs/remotes/svn/trunk
  • refs/remotes/svn/branch1
  • refs/remotes/svn/branch2

I can't use git clone --mirror because that creates a bare repository.

Why so complicated?

Our company is currently using svn. Meanwhile I'm preparing the migration from svn to git.

Unfortunately git svn fetch takes forever on my windows machine so I'm using a linux machine that does the git svn fetch periodically and then I copy the resulting git repo using FileZilla.


Solution

  • After cloning the repository normally, instruct Git to fetch the remote refs:

    git config --add remote.origin.fetch '+refs/remotes/svn/*:refs/remotes/svn/*'
    

    Subsequent git fetch calls will download the svn refs.