Git Cheat Sheet · Synchronize

Add a remote

git remote add <name> <url>

A remote is a distant repository you exchange commits with, usually on GitHub or GitLab. git remote add origin <url> declares it under the name "origin". A cloned repository already has one.

What it does

Declares a remote repository to exchange commits with.

A use case

You created your repository locally and now want to publish it on GitHub.

On the command line

git remote add origin <url>
Declares the main remote.
git remote -v
Lists remotes and their URLs.
git remote set-url origin <new-url>
Changes the URL, for example to move from HTTPS to SSH.
git remote rename <old> <new>
Renames a remote.
git remote remove <name>
Deletes a remote.
git remote add upstream <url>
On a fork, declares the original repository to follow its updates.

In Merathon

  1. In the left panel, click the "+" of the "Remote" section.
  2. Enter the name (usually "origin") then the URL.
  3. Right-click a remote → "Delete remote" to remove it.

Frequently asked questions

What does "remote origin already exists" mean?

A remote already has this name: change its URL with git remote set-url origin <url> instead of adding it.

How do I publish a local repository to GitHub?

Create an empty repository on GitHub, then git remote add origin <url> and git push -u origin main.

See also