2

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.

matthias.lukaszek
  • 2,200
  • 1
  • 23
  • 33
  • Possible duplicate of [Can "git pull --all" update all my local branches?](http://stackoverflow.com/questions/4318161/can-git-pull-all-update-all-my-local-branches) – René Höhle Feb 20 '17 at 14:54
  • Nope. This doesn't have anything to do with pulling / fetching from different remotes. – matthias.lukaszek Feb 20 '17 at 15:00
  • 1
    What i don't understand is why you don't switch completely to git? Why do you make such things with fetch and copy? – René Höhle Feb 20 '17 at 15:14
  • I had to do just this about a year ago, and I blogged about it. Could help. https://123code.co.uk/view/Resources/migrating-a-subversion-repository-to-git – DevDonkey Feb 20 '17 at 15:18
  • We are also bound to SVN at work currently. So until we switch to Git I'm also using `git-svn` to at least use git as frontend. I've setup a Windows task that runs every 15 minutes that does `git svn fetch` as long as I'm connected to work network. So I never miss more than 15 minutes which doesn't need much time and I can always do a rebase to bring in the latest changes into my local working branches. Works perfectly for me, maybe it is also the way to go for you. – Vampire Feb 20 '17 at 16:36
  • The repo is quite big, around 2000 branches, 200000 commits, 60000 files. `git svn fetch` takes around 5 to 20 minutes per commit on a windows machine and around 20 seconds on the linux VM in our data center. – matthias.lukaszek Feb 20 '17 at 17:12

1 Answers1

3

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.

j6t
  • 9,150
  • 1
  • 15
  • 35
  • Is there a way to download the refs once, as opposed to every time the remote is fetch-ed? – ryanwebjackson May 08 '20 at 12:37
  • @ryanwebjackson Sure, just unset the option after you are done: `git config --unset remote.origin.fetch 'refs/remotes/svn/'`. This is safe because the destination in the answer was given as `refs/remotes/svn/*`, which is outside the namespace of `origin` (that would be `refs/remotes/origin`), so `git fetch --prune origin` does not delete the one-time-fetched refs. – j6t May 09 '20 at 13:21
  • This makes sense, but it does not solve what I'm asking for. I don't want to unset the remote. I might post my own question. Thanks for replying. – ryanwebjackson May 25 '20 at 00:06