Skip to main content

How to Add a Remote in Git

Short answer

To add a remote to an existing local Git repository, run git remote add <name> <url>, where origin is the conventional name for the primary remote. Verify the remote was added correctly with git remote -v, which lists each remote alongside its fetch and push URLs. To push your local history to the new remote for the first time and set up tracking, run git push -u origin <branch-name>. If you need to change an existing remote's URL — for example after a repository was moved or renamed — use git remote set-url origin <new-url>. To remove a remote entirely, run git remote remove <name>; this deletes the remote configuration but does not affect the remote repository itself or any local files.

Cloning a repository from a remote server downloads the project to your local computer and leaves you with a local Git repository. This local Git repository will already have a connection to the original remote set up, automatically. This is what the "origin" remote connection points to.

But if you started by creating a local repository on your computer, there won't be such a connection. Let's look at how to add a remote in this short article!

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Adding a Remote

First, it's important to understand that origin is in no way a "special" name. In theory, you could name your remote connections any way you like. But the common, agreed-upon convention is to call a repository's main remote connection "origin" - which is why it makes sense to adhere to this naming scheme.

We're going to add a new remote connection to our local repository using the git remote command and need to pieces of information for this:

  1. The name we'd like for this new remote.
  2. The URL of the remote repository. You can find this after creating a new remote repo on your hosting service of choice (e.g. GitHub, GitLab, Bitbucket...).

Let's go:

git remote add origin https://github.com/gittower/example.git

You can easily check if the command has worked:

$ git remote -v
origin  https://gittower@github.com/gittower/example.git (fetch)
origin  https://gittower@github.com/gittower/example.git (push)

Voila, looks good!

No Command Line Needed

Adding a Remote in Tower

In case you are using the Tower Git client, you can add a remote repo easily through the "Add Remote Repository" dialog:

Learn More

Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!