How to mirror one one git remote to another with push

James Blackburn picture James Blackburn · Sep 8, 2009 · Viewed 9.2k times · Source

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?

Answer

Pat Notz picture Pat Notz · Sep 8, 2009

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!]