How to add a remote to git
git
add remote
git add remote
To add a new remote you need to use the git remote add command on the terminal in the root folder of your repository.
The git remote add
command has two parameters:
- the remote name, the most used name is
origin
, but if you have multiple repositories to push more suggestive names are recommended. I will go withgitlab
- the remote URL, for example,
https://gitlab.com/admfactory/jersey-hello-world.git
Add
C:\Users\adm\repos\jersey-hello-world>git remote add gitlab https://gitlab.com/admfactory/jersey-hello-world.git
Verify
To check the remote was added run the following command:
C:\Users\adm\repos\jersey-hello-world>git remote -v
gitlab https://gitlab.com/admfactory/jersey-hello-world.git (fetch)
gitlab https://gitlab.com/admfactory/jersey-hello-world.git (push)
origin https://github.com/admfactory/jersey-hello-world.git (fetch)
origin https://github.com/admfactory/jersey-hello-world.git (push)
Errors
If the remote is already present the following error will occur:
C:\Users\adm\repos\jersey-hello-world>git remote add gitlab https://gitlab.com/admfactory/jersey-hello-world.git
fatal: remote gitlab already exists.