Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Git Remotes  ›  Lesson

Managing Remotes

Managing Remotes 12 minA remote is a local nickname for another copy's URL, managed with git remote add, -v, rename, set-url and remove, and it produces remote-tracking branches such as origin/main.

Managing Remotes

A remote is just a saved nickname for another copy of the repository, usually on a server. Ravi's clone got one automatically. Asha started with git init, so her repository knows about no remotes until she adds one. Either way, a handful of commands manage the list.

The rule

A remote is a nickname for a URL; add, list, rename, re-point or remove it.

git remote -v                                    # list remotes and their URLs
git remote add origin https://github.com/asha-dev/recipe-box.git
git remote set-url origin git@github.com:asha-dev/recipe-box.git   # new URL
git remote rename origin github                  # change the nickname
git remote remove github                         # forget a remote

Key facts:

  • origin is only a convention. It is the name Git gives the place you cloned from, and the name most people choose when adding their main remote. Nothing about it is special.
  • A repository can have many remotes. When you contribute to someone else's project, it is common to have origin for your own copy and upstream for the original.
  • Removing a remote deletes nothing on the server. It only removes the nickname, and the remote-tracking branches, from your local repository.
  • git remote -v shows two lines per remote, one marked (fetch) and one (push). They are normally the same URL.

Remotes also create remote-tracking branches such as origin/main. These are your repository's memory of where each branch was on the remote the last time you talked to it. They update only when you fetch, pull or push, never on their own.

Inspect one remote in detail with:

git remote show origin

It lists the remote's branches and which of your local branches push to and pull from them.

The shortcut

Treat remotes like contacts in a phone: one name, one address. Wrong address? set-url. Wrong name? rename. Not needed? remove. Unsure? git remote -v and look.

Asha connects her repositoryStep 1 of 4
  1. Nothing yet

    Asha's repository began with git init, so git remote -v prints nothing.

A common error is remote origin already exists, which appears when you run git remote add origin twice. You do not need to add it again; use set-url to change the address.

Drills

Answer fast — trust the rule.

quick drill

Which command lists your remotes with their URLs?

quick drill

git remote add origin <url> fails with "remote origin already exists". Asha wants the new URL. What should she run?

quick drill

What happens on GitHub when Asha runs git remote remove origin?

quick drill

What is origin/main?

Remember

  • A remote is a nickname for a URL; add, list, rename, re-point or remove it.
  • origin is a convention, not magic; upstream is common for an original project.
  • Removing a remote changes nothing on the server.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainName and address

Asha's repository started with git init. Explain how she connects it to her GitHub repository, how she later switches it from an HTTPS URL to an SSH URL, and what origin/main represents.