Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

Git Move Repository

20190626 This use case moves a github repository into a new one whilst retaining history and issues, etc. You will need at least write access to the new repository.

To begin the move from the source repository u1/pygym to the target repository u2/pygym, change into the source repository's local clone. In the u1/pygym folder 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

Now overwrite the history of u2/pygym with u1/pygym using push. Using --all ensures all branches are pushed. The use of --force ensures the destination repository is effectively obliterated without question. The use of --tags is optional to ensure the commit tags are retained in the new repository:

$ git push --all --force new-origin
$ git push --tags --force new-origin

Next 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

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

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


Copyright © 1995-2019 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.