How to remane a remote from git
git
rename remote
To rename a remote you can use the command git remote rename
in the terminal, from the root folder of your repository.
The git remote rename
command has two parameters:
- the existing remote name;
- the new name for the remote;
Rename
Will rename the origin
remote to github
.
C:\Users\adm\repos\jersey-hello-world>git remote rename origin github
To check the remote names run the following command:
C:\Users\adm\repos\jersey-hello-world>git remote -v
github https://github.com/admfactory/jersey-hello-world.git (fetch)
github https://github.com/admfactory/jersey-hello-world.git (push)
gitlab https://gitlab.com/admfactory/jersey-hello-world.git (fetch)
gitlab https://gitlab.com/admfactory/jersey-hello-world.git (push)
Errors
If the remote name is already present the following error will occur:
fatal: remote gitlab already exists.
If the origin remote doesn't exist the following error will occur:
error: Could not rename config section 'remote.origin' to 'remote.github'