linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Remote repositories/remote-cmd

kb/remote ── Remote repositories ── beginner

git remote

Manages the list of URLs your repository is connected to. After `clone` there is one remote named `origin` by default. You can add a second one (`upstream` for fork flow), remove remotes, or rename them.

view as markdownaka: git-remote

A remote is just a name for a URL. Inside .git/config each remote has a section:

[remote "origin"]
    url = git@github.com:foo/bar.git
    fetch = +refs/heads/*:refs/remotes/origin/*

The git remote command reads and edits this list.

Core commands

bash
git remote                          # list names
git remote -v                       # with URLs and directions
git remote show origin              # detailed info: branches, tracking
git remote add upstream <url>       # add a remote
git remote rename origin foo        # rename
git remote remove upstream          # remove
git remote set-url origin <new>     # change URL without re-cloning

Typical output of git remote -v:

origin    git@github.com:me/bar.git (fetch)
origin    git@github.com:me/bar.git (push)
upstream  git@github.com:original/bar.git (fetch)
upstream  git@github.com:original/bar.git (push)

The two directions (fetch and push) can point to different URLs (rare case: pull from one, push to another). Usually they are the same.

Why "origin"

Just a name. Git defaults to cloning from origin because that is the convention. You can rename it:

bash
git remote rename origin upstream

In the fork scenario (see fork-vs-clone):

  • origin is your fork (me/repo).
  • upstream is the original repository (original/repo).

More detail in upstream-vs-origin.

Change URL without re-cloning

Scenario: the repository moved from GitHub to GitLab. No need to clone again:

bash
git remote set-url origin git@gitlab.com:foo/bar.git
git fetch

Everything continues to work, history intact.

Separate push URL and fetch URL

Sometimes you need to pull from a public mirror but push to a private one:

bash
git remote set-url origin https://github.com/foo/bar.git
git remote set-url --push origin git@gitlab.com:foo/bar.git

Now git fetch goes to GitHub and git push goes to GitLab. Rare, but useful during migrations.

Pitfalls

  • git remote add does NOT fetch automatically. After adding, you need git fetch <name>, otherwise the new remote's branches will not appear.
  • The URL is stored in .git/config in plain text. If the URL contains a password (https://user:password@...) it sits there unencrypted. Use SSH or a credential helper instead.
  • Remote names are local. Your upstream may point to one place, your colleague's to another. That is normal, but when talking in a team, refer to the URL, not the name.

§ команды

bash
git remote -v

List all remotes with their URLs

bash
git remote add upstream <url>

Add a second remote, typically the original repo in fork flow

bash
git remote set-url origin <new-url>

Change URL without re-cloning

bash
git remote show origin

Detailed info: which branches are tracked and which are not

§ см. также

  • clonegit cloneCreates a local copy of a remote repository. Under the hood: `init` + add origin + `fetch` the full history + `checkout` the default branch. The first command you run on any project you did not create yourself.
  • fetchgit fetchDownloads updates from a remote but **does not touch** your local branches. Updates only refs/remotes/origin/. A safe command: after fetch you can see what arrived and decide what to do with it.
  • upstream-vs-originupstream vs originTwo conventional remote names. `origin` is where you cloned from (usually your fork). `upstream` is the "real" project you forked. This is just a convention: nothing is magic, both names can be renamed.
  • fork-vs-cloneFork vs cloneClone is a local copy of a repository. Fork is a copy **on the server** under your account. In open source you usually fork first (gaining write access to your copy), then clone the fork (to work locally), and open a PR from the fork back to the original.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies