Migrating Git Repositories with History

Summary

This is a very simple post detailing how to mirror a repo to a new account. I have repositories under other github accounts and on private git servers that I wanted to consolidate.

Steps

git clone --mirror URL/REPO.git
  1. Clone the repo with a --mirror tag. This will create a REPO.git directory.

  2. Create a new repository on the server you would like to mirror to, lets call the address to this: NEW-REPO-URL. Note: the new repository doesn’t have to have the same name.

cd REPO.git
  1. Change to the newly mirrored repo
git remote set-url --push origin NEW-REPO-URL
  1. Add the address to the new repo as a remote origin
git push --mirror
  1. Push the repo to the new server/account.

Notes

All the branches and commit history should be available in the new repository. However, I did notice that some repositories that I mirrored from GitHub Enterprise servers had my username as GitHub Enterprise. Unsure of how to fix that for now, but it isn’t a deal breaker for my particular use case.

Avatar
Saqib Nizami
Data Scientist

coding, data science, statistics, development of all kinds.