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 -vorigin is a conventional name, not a special server or reserved keyword.
Inspect more details:
git remote show origin
git remote get-url originCloning normally creates the origin remote automatically:
git clone https://github.com/ORG/PROJECT.gitRemote-Tracking Branches
After fetching, Git records its latest knowledge of remote branches using names such as:
origin/main
origin/feature-apiorigin/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 branchgit fetch
git fetch originFetching 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/mainAfter review, integrate deliberately:
git merge origin/mainRebase 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-onlyOr separate the operations:
git fetch origin
git log --oneline main..origin/main
git merge origin/mainThe separate form is useful while learning because the downloaded commits can be inspected before integration.
git push
git push -u origin mainThis 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-onlyPush 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
| Command | Main effect | Changes current working files? |
|---|---|---|
git clone <url> | Create a new local repository and initial checkout | Yes, during clone setup |
git fetch <remote> | Download objects and update remote-tracking references | Normally no |
git pull | Fetch and integrate into the current branch | Usually yes |
git push | Send commits and request remote reference updates | No |
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 -vA common fork workflow uses:
originfor the contributor’s writable forkupstreamfor 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-onlyThe 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
originalways exists in a repository created withgit init - Confusing the local branch
mainwith the remote-tracking referenceorigin/main - Expecting
git fetchto update working files - Running
git pullwithout knowing the configured integration policy - Expecting
git pushto 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.
originis a convention automatically created by a normal clone.fetchupdates local knowledge of the remote without normally changing working files.pullperforms a fetch followed by integration.pushpublishes 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.