A Git remote is a named reference to another repository. It may be hosted on an internal server, GitHub, GitLab, Bitbucket, a filesystem path, or another service that supports a Git transport.

The remote is not automatically the only or central repository. Teams usually designate one hosted repository as the official integration point, but Git can work with several remotes.

Local and Remote Data Flow

flowchart LR
    Remote["Remote repository"]
    Local["Local repository"]
    Index["Staging area"]
    Working["Working tree"]

    Remote -->|"git clone or git fetch"| Local
    Local -->|"git push"| Remote
    Working -->|"git add"| Index
    Index -->|"git commit"| Local
    Local -->|"checkout, merge, rebase, or restore"| Working

git clone is a setup operation that creates the local repository and working tree. Routine synchronization then uses fetch, pull, and push.

Add and Inspect a Remote

If a repository was created with git init, add a remote explicitly:

git remote add origin https://github.com/ORG/PROJECT.git
git remote -v

origin is a conventional name, not a special server or reserved keyword.

Inspect more details:

git remote show origin
git remote get-url origin

Cloning normally creates the origin remote automatically:

git clone https://github.com/ORG/PROJECT.git

Remote-Tracking Branches

After fetching, Git records its latest knowledge of remote branches using names such as:

origin/main
origin/feature-api

origin/main is a local remote-tracking reference. It is not the live branch on the server, and it changes only when the local repository communicates with that remote.

main          → local branch
origin/main   → local record of the fetched remote branch

git fetch

git fetch origin

Fetching downloads objects and updates remote-tracking references. It does not normally merge those commits into the current local branch or replace working-tree files.

This makes fetching a useful inspection step:

git log --oneline main..origin/main
git diff main..origin/main

After review, integrate deliberately:

git merge origin/main

Rebase is another integration strategy, but it rewrites the local commits being replayed and should be learned separately before using it on shared work.

git pull

git pull first fetches and then integrates the selected remote branch into the current branch.

Depending on command options and configuration, integration can use a merge, rebase, or fast-forward-only policy. Saying that pull always merges is incomplete.

# Refuse the pull unless it can advance without a merge commit
git pull --ff-only

Or separate the operations:

git fetch origin
git log --oneline main..origin/main
git merge origin/main

The separate form is useful while learning because the downloaded commits can be inspected before integration.

git push

git push -u origin main

This asks Git to update the main branch at origin using the local main branch. -u records the upstream relationship so later commands can usually be shorter:

git push
git pull --ff-only

Push sends reachable Git objects and requests reference updates. It does not send:

  • unstaged working-tree edits
  • staged but uncommitted content
  • ignored files that were never committed
  • unrelated files elsewhere on the machine

If the remote branch contains commits the local branch does not have, a normal push is usually rejected as non-fast-forward. Fetch and integrate the other work instead of overwriting it.

Clone, Fetch, Pull, and Push

CommandMain effectChanges current working files?
git clone <url>Create a new local repository and initial checkoutYes, during clone setup
git fetch <remote>Download objects and update remote-tracking referencesNormally no
git pullFetch and integrate into the current branchUsually yes
git pushSend commits and request remote reference updatesNo

Multiple Remotes

A project can use more than one remote:

git remote add origin https://github.com/USER/PROJECT.git
git remote add upstream https://github.com/ORG/PROJECT.git
git remote -v

A common fork workflow uses:

  • origin for the contributor’s writable fork
  • upstream for the original project

The names are conventions. The configured URLs and permissions determine what each remote does.

Authentication Is Separate

The author name and email stored in Git configuration do not authenticate a push.

Remote access commonly uses:

  • HTTPS with a credential helper, token, or organization-specific login flow
  • SSH keys
  • enterprise identity and access controls supplied by the hosting platform

Do not place access tokens in a repository URL committed to a script or configuration file.

Corrected End-to-End Example

git init -b main
git add switch.cfg
git commit -m "Add initial switch configuration"
 
git remote add origin https://github.com/ORG/NETWORK-CONFIGS.git
git remote -v
 
git push -u origin main
git fetch origin
git pull --ff-only

The remote is named origin, so the push command must use origin. A command such as git push local main works only if a remote named local was actually configured.

Common Mistakes

  • Assuming origin always exists in a repository created with git init
  • Confusing the local branch main with the remote-tracking reference origin/main
  • Expecting git fetch to update working files
  • Running git pull without knowing the configured integration policy
  • Expecting git push to include uncommitted changes
  • Force-pushing over other contributors’ commits
  • Embedding credentials in remote URLs

TL;DR

  • A remote is a named reference to another Git repository.
  • origin is a convention automatically created by a normal clone.
  • fetch updates local knowledge of the remote without normally changing working files.
  • pull performs a fetch followed by integration.
  • push publishes commits, not uncommitted files.
  • Remote authentication is separate from commit author identity.

Resources

Continue with Undoing Changes for stashing work and choosing between restore, reset, and revert.

Note: Remote behaviour and command options were checked against current Git documentation in July 2026.