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

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. Any content of the new repository will be overwritten.

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

$ 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 master

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 argued as the better solution.


Support further development by purchasing the PDF version of the book.
Other online resources include the Data Science Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.