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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)