If you had a local repo and a remote repo connected to it (say on GitHub) - and for some reason you decide to change the repo name on remote, what do you need to do locally to keep things working? (as push/fetch/pull from local start to fail due to rename)
Rename the remote repo(1,2), and then tweak the local repo(3,4,5) so that things work as expected:
- Go to the remote host (for example,
https://github.com/user/project
). - Rename the repo following the host’s instructions (may differ from host to host, but you should be able to find it under Settings).
- Determine the new URL (for example,
git@github.com:user/project-new.git
) - Go to your local repository directory (i.e., open a command prompt and cd to the repository’s directory).
- Set the new URL using Git:
git remote set-url origin git@github.com:user/project-new.git
and your push/pull/fetch should start working as usual
EDIT:
I later found out that in case of GitHub, it automatically takes care of repo rename - it continues to remember the old repo URL and any push
, clone
, fetch
done on old remote URL is automatically redirected to the new URL.
However they do recommend changing URL on local As described in this article to avoid any confusion
What could be the confusion you ask? As also mentioned in above GitHub documentation:
Warning: If you create a new repository under your account in the future, do not reuse the original name of the renamed repository. If you do, redirects to the renamed repository will break.
I faced this problem! and had to use the changing remote URL.
- Changed remote repo name from A to B.
- Created a new repo with name A
- Faced problem with local B push etc.
So be safe - if you rename a Remote repo also update the local remote repo URL