How to Add a Git Remote

By 

Updated on

5 min read

Git logo with Add Git Remote title

When you work with Git, you usually use a single remote named origin and separate branches for different features and environments. Origin is the remote that Git creates automatically when you clone a repository, and it points to the repository you cloned from.

When you collaborate on a project with a group of people, or push the same code to more than one server, adding extra remotes is useful. A Git remote is a pointer to a copy of the repository, typically hosted on another server.

This guide explains how to add a new Git remote, list and inspect the remotes you have, and push code to them.

Adding a Git Remote

The remote repository must exist before you add it to your local repository. You can create one on a Git hosting service such as GitHub, GitLab, or Bitbucket, or on your own private Git server .

To add a new remote, navigate to the directory where your repository is stored and run the git remote add command followed by the remote name and the remote URL:

txt
git remote add <remote-name> <remote-url>

For example, to add a new remote named staging that points to the git@github.com:octocat/Hello-World.git URL, you would type:

Terminal
git remote add staging git@github.com:octocat/Hello-World.git

The command produces no output when it succeeds. Behind the scenes, git remote add modifies the repository .git/config file and adds a new connection to the remote repository:

.git/configini
...

[remote "staging"]
        url = git@github.com:octocat/Hello-World.git
        fetch = +refs/heads/*:refs/remotes/staging/*

You can also add a remote by editing the .git/config file with a text editor , but running the command is easier and less error-prone.

Listing and Inspecting Remotes

To verify that the new remote was added, list the configured remotes with the git remote command. The -v (verbose) flag also prints the URLs:

Terminal
git remote -v

The output shows each remote together with its fetch and push URLs:

output
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)

Notice that the new staging remote now appears alongside origin.

For more detail about a single remote, including its tracked branches and the branches configured for git pull and git push, use git remote show followed by the remote name:

Terminal
git remote show staging
output
* remote staging
  Fetch URL: git@github.com:octocat/Hello-World.git
  Push  URL: git@github.com:octocat/Hello-World.git
  HEAD branch: master
  Remote branches:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

This command contacts the remote server, so it requires network access and valid credentials.

Pushing and Pulling

Once the remote is added, you can push a local branch to it by passing the remote name and the branch name:

Terminal
git push <remote-name> <branch-name>

To download changes from the remote, use git fetch to retrieve the objects without merging, or git pull to fetch and merge into the current branch:

Terminal
git fetch <remote-name>
git pull <remote-name> <branch-name>

If you are unsure which one to use, see our guide on git fetch vs git pull .

Managing Existing Remotes

Adding a remote is only one part of working with remotes. Once a remote exists, you can rename it with git remote rename <old-name> <new-name>. When a repository moves to a new host or switches between HTTPS and SSH, you do not need to recreate the remote; see how to change a Git remote’s URL instead. To delete a remote you no longer use, follow our guide on how to remove a Git remote .

Quick Reference

For a printable quick reference, see the Git cheatsheet .

CommandDescription
git remote add <name> <url>Add a new remote
git remote -vList remotes with their URLs
git remote show <name>Show details about a remote
git remote rename <old> <new>Rename a remote
git remote set-url <name> <url>Change a remote’s URL
git remote remove <name>Remove a remote
git push <name> <branch>Push a branch to a remote
git fetch <name>Download objects from a remote

Troubleshooting

fatal: remote <name> already exists
A remote with that name is already configured. Choose a different name, update the existing remote with git remote set-url, or remove it first with git remote remove <name> and add it again.

fatal: '<name>' does not appear to be a git repository
The remote URL is wrong or unreachable. This error appears on push or fetch, not when adding the remote. Confirm the URL with git remote -v and check that the repository exists and you have access to it.

Could not read from remote repository
Git could not authenticate with the remote. Verify your SSH keys or credentials and confirm that your account has permission to access the repository.

FAQ

What is the origin remote?
origin is the default name Git assigns to the remote it cloned from. It is a convention, not a requirement, so you can rename it or add other remotes with any name you choose.

Can a repository have multiple remotes?
Yes. Add as many remotes as you need with git remote add, giving each a distinct name. This is common when you push the same code to several hosts or contribute to a fork and its upstream project.

How do I change the URL of an existing remote?
Use git remote set-url <name> <new-url>, or follow our detailed guide on changing a Git remote’s URL .

How do I remove a remote?
Run git remote remove <name>. For more detail, see how to remove a Git remote .

Conclusion

Adding a Git remote takes a single git remote add command, after which you can list it with git remote -v, inspect it with git remote show, and push to it. Combine remotes with branches to share work across multiple repositories and servers.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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