Git Remote: Connect Your Repo to a Remote Server
A Git remote is a reference to a copy of your repository hosted elsewhere: GitHub, GitLab, Bitbucket, or your own server. This guide explains how to add, inspect, rename, and remove remotes, and how remote tracking branches work.
Beginner8 min readUpdated
What is a Git remote?
A Git remote is a named reference to a repository hosted somewhere else: GitHub, GitLab, Bitbucket, or any server. The most common remote is origin, which Git creates automatically when you clone a repository.
The short version
- 1List remotes:
git remote -v - 2Add a remote:
git remote add origin <url> - 3Fetch from remote:
git fetch origin - 4Push and set tracking:
git push -u origin main - 5Clean up stale refs:
git remote prune origin
Why it matters
You've initialized a local repository and written some commits, but you have no idea how to connect it to GitHub or push your work anywhere. Or you're trying to pull from a second remote and Git says it doesn't know where to look.
Remotes are the bridges between your local repository and the rest of the world. Understanding how to add, list, and manage them is essential for any collaborative workflow, whether you're pushing to GitHub, pulling from an upstream fork, or working with multiple team servers.
Where it usually goes wrong
- Forgetting to add a remote after
git init, then being unable to push - Confusing
origin(your fork) withupstream(the original project) - Pushing to the wrong remote by accident
- Not knowing that remote tracking branches like
origin/mainare just local snapshots
Git remote, step by step
Step 1: List existing remotes
Start by checking what remotes are already configured in your repo.
Terminalgit remote -v# origin git@github.com:user/my-project.git (fetch)# origin git@github.com:user/my-project.git (push)Tip: If you cloned the repo,
originis already set. If you rangit init, there are no remotes yet.Step 2: Add a remote
Connect your local repo to a remote repository.
originis the conventional name for your primary remote.Terminalgit remote add origin git@github.com:user/my-project.git# Verify:git remote -vStep 3: Add a second remote (upstream)
When working with a forked project, add the original repository as
upstreamso you can pull in updates from it.Terminalgit remote add upstream git@github.com:original-owner/my-project.git# Fetch the upstream branches:git fetch upstreamStep 4: Rename a remote
If you need to rename an existing remote (e.g., from
origintogithub):Terminalgit remote rename origin githubStep 5: Remove a remote
Remove a remote that is no longer needed. This only deletes the reference. It doesn't delete anything on the remote server.
Terminalgit remote remove upstream
In Gitoryx: Remotes and their branches appear directly in the commit graphHow it works Step 6: Change a remote URL
If a repository moves, or you want to switch from HTTPS to SSH:
Terminalgit remote set-url origin git@github.com:user/new-location.git# Verify the change:git remote -vStep 7: Inspect a remote in detail
git remote showgives you a full picture of a remote: its URL, all tracked branches, and which local branches are configured to push/pull from it.Terminalgit remote show origin# Output:# * remote origin# Fetch URL: git@github.com:user/my-project.git# Push URL: git@github.com:user/my-project.git# HEAD branch: main# Remote branches:# develop tracked# main tracked# Local branch configured for 'git pull':# main merges with remote main# Local ref configured for 'git push':# main pushes to main (up to date)Tip: Run
git remote show originbefore pushing to an unfamiliar remote to confirm you're targeting the right branch.Step 8: Understand remote-tracking branches
Remote-tracking branches like
origin/mainare local read-only snapshots of what the remote looked like the last time you fetched. They update only when you rungit fetchorgit pull.Terminal# See all remote-tracking branchesgit branch -r# origin/HEAD -> origin/main# origin/develop# origin/main# Compare your local main with the remote snapshotgit log origin/main..main # commits you have locally but remote doesn'tgit log main..origin/main # commits on remote that you don't have yet# Update all remote-tracking branches without merginggit fetch --allTip:
origin/mainis NOT the same asmain. It's a cached snapshot. Alwaysgit fetchbefore comparing branches.Step 9: Clean up stale remote-tracking branches
After remote branches are deleted (e.g., after a merged PR), their local tracking references stick around.
git remote prunecleans them up.Terminal# See which remote-tracking refs are stale (dry run)git remote prune origin --dry-run# Actually remove the stale refsgit remote prune origin# Combine fetch + prune in one commandgit fetch --prune# Or configure git to always prune on fetch:git config --global fetch.prune trueCareful:
git remote pruneonly removes your local tracking refs. It does NOT delete anything on the remote server. It's always safe to run.
Mistakes to avoid with git remote
- Mixing up origin and upstream
- When working on a fork,
originis your copy,upstreamis the original. Pushing to upstream (if you don't have write access) fails; pulling from origin instead of upstream misses new changes from the source project. - Fix: Always confirm with
git remote -vbefore pushing or pulling. - Not fetching before checking remote tracking branches
origin/mainis a local snapshot of the remote branch. It only updates when you fetch.- Fix: Run
git fetch originto update all remote tracking branches before comparing or merging. - Forgetting to set upstream when pushing a new branch
- Git says 'The current branch has no upstream branch' when you try to push a branch for the first time.
- Fix: Use
git push -u origin <branch>the first time. The-uflag sets the tracking relationship.
Git remote in Gitoryx
Gitoryx lists all your remotes in the sidebar, shows their tracking branches in the commit graph, and lets you fetch, pull, or push to any remote in one click.
- Remotes and their branches appear directly in the commit graph
- Add, rename, or remove remotes from the sidebar: no CLI needed
- Fetch all remotes at once with a single click
- See at a glance if your branch is ahead or behind origin
Free plan · no account required · macOS, Windows and Linux
Git remote: frequently asked questions
- What is `origin` in Git?
originis the default name Git gives to the remote from which you cloned. It's just a shorthand alias for the full remote URL. You can rename it or have multiple remotes with different names.- What is the difference between origin and upstream in Git?
- When you fork a project,
originis your personal fork andupstreamis the original repository you forked from. You push toorigin(your fork) and pull updates fromupstream(the source). This is a naming convention, not enforced by Git. - What is the difference between `git fetch` and `git pull`?
git fetchdownloads new data from the remote and updates remote tracking branches (likeorigin/main) but does not change your local branch.git pulldoes a fetch followed by a merge (or rebase) into your current branch.- Can I have multiple remotes?
- Yes. You can add as many remotes as you need. Common setups include
origin(your fork) andupstream(the original project), or multiple deployment targets likeorigin,staging, andproduction. - How do I push to a remote for the first time?
- Use
git push -u origin <branch-name>. The-uflag sets the tracking relationship so futuregit pushandgit pullcommands know which remote branch to use. - What is a remote-tracking branch?
- A remote-tracking branch (e.g.,
origin/main) is a local, read-only snapshot of what a remote branch looked like the last time you fetched. It updates only when you rungit fetchorgit pull. Usegit branch -rto list all remote-tracking branches. - How do I remove stale remote-tracking branches?
- Run
git remote prune originto delete local references to remote branches that no longer exist. Usegit fetch --pruneto do the same automatically every time you fetch. This is safe: it only removes local refs, not anything on the remote. - How do I change a remote URL in Git?
- Run
git remote set-url origin <new-url>. This is useful when switching from HTTPS to SSH, or when a repository moves. Verify the change withgit remote -v.
Related reading
- Git Clone: How to Copy a RepositoryTutorial · 8 min
- Git Pull: Sync Your Branch with the RemoteTutorial · 8 min
- Git Push: Upload Your Commits to a Remote RepositoryTutorial · 8 min