GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
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 88.9):
$ 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.