How to mirror one one git remote to another with push
Asked Answered
C

3

7

The problem is a simple one. I've used git cvsimport to import a cvs repo into a remote branch in a local git repository. I then wish to sync this repository: branches, tags, and all, to a git repository in the cloud (github / gitorious). To do this I don't have the access to rsync or copy the repository directly, I have to use git push.

How do I go about mirroring my local repository so others have access to the full _cvsimport_d history?

Concretely:
I import and track a repository using cvsimport:

git cvsimport -i -v -C cdt-make-core -d :pserver:[email protected]:/cvsroot/tools -r cvs org.eclipse.cdt/all/org.eclipse.cdt.make.core

The above imports org.eclipse.cdt.make.core into the remote cvs in the git repo cdt-make-core.

I can then push the HEAD of the main CVS branch to github:

git push github cvs/master:refs/heads/cvs/HEAD

(I specify the path on the remote explicitly so if it doesn't exist it's created.)

Is there any way to sync all the branches: cvs/* => cvs/* on the remote?
Is there any way to sync all the tags?

Ca answered 8/9, 2009 at 9:19 Comment(0)
D
3

My findings are that if you use the 2nd reasonable solution below, you need to do the --mirror first, because it wipes out those cvs/ branches you're trying to push. So the complete formula is:

git push --mirror -v github
git push --force github cvs/master:refs/heads/cvs/HEAD
for x in `git branch -r | grep '^..cvs/[a-zA-Z0-9_-]*$' | sed -e 's/^..//'` ; do  
  git push -v github $x:refs/heads/$x
  git config branch.$x.remote github
  git config branch.$x.merge refs/heads/$x
done
Doodle answered 29/1, 2010 at 17:21 Comment(0)
K
5

I think you're looking for the --mirror option to push:

git push --mirror github

This will push all refs (branches and tags) including non-fast-forward updates. I use this for creating backups of my local repository.

The man page describes it like this:

Instead of naming each ref to push, specifies that all refs under $GIT_DIR/refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.

[OT: I use CDT in my everyday work and I love it!]

Kilar answered 8/9, 2009 at 15:28 Comment(2)
Thanks. Unfortunately this doesn't seem to do what I want. It looks like this makes the repository in the cloud look like mine which means the github repo has a 'cvs' remote, but no visible cvs branches. What I wanted was to copy the full contents of the remotes/cvs/* to cvs/* on github.Ca
Ahh, I see now. Sorry for the dead end.Kilar
D
3

My findings are that if you use the 2nd reasonable solution below, you need to do the --mirror first, because it wipes out those cvs/ branches you're trying to push. So the complete formula is:

git push --mirror -v github
git push --force github cvs/master:refs/heads/cvs/HEAD
for x in `git branch -r | grep '^..cvs/[a-zA-Z0-9_-]*$' | sed -e 's/^..//'` ; do  
  git push -v github $x:refs/heads/$x
  git config branch.$x.remote github
  git config branch.$x.merge refs/heads/$x
done
Doodle answered 29/1, 2010 at 17:21 Comment(0)
C
1

Having experimented, I don't believe there's any built-in support for what I wish to do.

However there seem to be two reasonable solutions:

  • Don't specify -r to cvsimport.
    The imported branches will then exist directly in the repository and --mirror can be used as Pat suggested.
  • Write a shell script to push the *cvs/** remotes one at a time (which is straightforward).
    Use --mirror so that tags are correctly synced

I originally wanted to keep the cvsimportd branches separate for namespacing. However with the first option it makes sense to keep the cvsimport repository entirely separate (and only clone from it). I can then continue to track CVS with no risk of dirtying the tracking git repo.

Ca answered 15/9, 2009 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.