Mar 232020

ADM

How to add a remote to git

  • 23 March 2020
  • ADM

 

 

 

How to add a remote to git - images/logos/git.jpg

 

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 with gitlab
  • 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.

 

 

 

References