Read more

How to mirror a git repo to a new remote

Tobias Kraze
January 10, 2018Software engineer at makandra GmbH

Say you want to move a git repository from one remote (perhaps Github) to another (perhaps Gitlab).

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

If you have the repo checked out, you still should make sure to mirror all branches of the old remote, not only those you happen to have checked our. Otherwise the target repo will become a copy of your current repo, and not the source repo, potentially missing commits. You can use this:

git remote rename origin old-origin
git remote add origin <new-remote>
git fetch old-origin --prune
git push --prune origin +refs/remotes/old-origin/*:refs/heads/* +refs/tags/*:refs/tags/*

Note that the last push is effectively a "force push", and will set all branches on the new remote to exactly the branches on the old remote, even if your local branches are ahead.

To make sure, everything worked as expected, check that the latest revision on the old remote of some branch is present on the new remote.

Posted by Tobias Kraze to makandra dev (2018-01-10 18:43)