33.25 Git Move Repository

20200316

This use case moves a git repository (pygym) from one user (u1) to another user (u2) while retaining history and issues, etc. You will need read access to the old repository and write access to the new repository.

To begin, clone the source repository u1/pygym and ensure the destination repository already exists (or create the repository as explained in Section @ref(sec:git_create_repo)):

git clone git@github.com:u1/pygym.git

Change into the source repository’s local clone and add u2/pygym.git as a remote to u1/pygym, calling it the new-origin:

$ git remote add new-origin git@github.com:u2/pygym.git
$ git remote -v
new-origin git@github.com:u2/pygym.git (fetch)
new-origin git@github.com:u2/pygym.git (push)
origin git@github.com:u1/pygym.git (fetch)
origin git@github.com:u1/pygm.git (push)

Overwrite the history of u2/pygym with u1/pygym using push as below. The option -{-all} ensures all branches are pushed. The use of -{-force} ensures the destination repository is effectively obliterated without question (be careful):

git push --all --force new_origin

Remove the remote u1/pygym and then rename the remote so that any future git push will directly got into u2/pygym instead of u1/pygym. This effectively maps the current local repository to be a clone of the new remote repository.

git remote rm origin  
git remote rename new_origin origin
git push --set-upstream origin main

Further details from https://github.com/simonzhaoms/githubtest/blob/main/move-repo.md.

See also https://help.github.com/en/articles/transferring-a-repository. This requires additional permissions, but is argued as the better solution.



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0