How To Add a Git Remote

Usually, when working with Git, you’ll use only one remote named origin and different branches for different features and environments. Origin is the name of the remote that automatically created when you clone a repository and points to the cloned repository.
However, when collaborating on a project with a group of people, you may find using multiple Git remotes very handy.
Git remotes are pointers to the versions of the repository that are typically stored on other servers.
This guide explains how to add a new Git remote.
Adding a Git Remote
The remote repository must exist before you add the git remote to your local repository. You can create the repository on a Git hosting service such as GitHub, GitLab, and BitBucket or on your private Git server .
To add a new remote, navigate to the directory
your repository is stored at and use the git remote add command followed by the remote name, and the remote URL:
git remote add <remote-name> <remote-url>For example, to add a new remote named staging pointing to the git@github.com:octocat/Hello-World.git URL you would type:
git remote add staging git@github.com:octocat/Hello-World.gitUse the git remote command to list the remote connections and verify that the new remote was successfully added:
git remote -vThe output will look something like this:
origin https://github.com/octocat/Hello-World.git (fetch)
origin https://github.com/octocat/Hello-World.git (push)
staging git@github.com:octocat/Hello-World.git (fetch)
staging git@github.com:octocat/Hello-World.git (push)What the git remote add command actually does is modify the repository .git/config file and a new connection to the remote repository.
...
[remote "staging"]
url = git@github.com:octocat/Hello-World.git
fetch = +refs/heads/*:refs/remotes/staging/*You can add a new remote by editing the .git/config file with a text editor
, but using the command is much easier.
That’s it. You have successfully added a new Git remote.
To push your code to the new remote, you would use:
git push <remote-name> <branch-name>To fetch and pull from the remote use:
git fetch <remote-name>
git pull <remote-name>Conclusion
Adding a new Git remote is just a matter of one command. Git remotes are very useful and allow you to have multiple repositories.
If you hit a problem or have feedback, leave a comment below.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page