Back
GitoryxGitoryx

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

On this page

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

  1. 1List remotes: git remote -v
  2. 2Add a remote: git remote add origin <url>
  3. 3Fetch from remote: git fetch origin
  4. 4Push and set tracking: git push -u origin main
  5. 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) with upstream (the original project)
  • Pushing to the wrong remote by accident
  • Not knowing that remote tracking branches like origin/main are just local snapshots

Git remote, step by step

  1. Step 1: List existing remotes

    Start by checking what remotes are already configured in your repo.

    Terminal
    git 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, origin is already set. If you ran git init, there are no remotes yet.

  2. Step 2: Add a remote

    Connect your local repo to a remote repository. origin is the conventional name for your primary remote.

    Terminal
    git remote add origin git@github.com:user/my-project.git# Verify:git remote -v
  3. Step 3: Add a second remote (upstream)

    When working with a forked project, add the original repository as upstream so you can pull in updates from it.

    Terminal
    git remote add upstream git@github.com:original-owner/my-project.git# Fetch the upstream branches:git fetch upstream
  4. Step 4: Rename a remote

    If you need to rename an existing remote (e.g., from origin to github):

    Terminal
    git remote rename origin github
  5. Step 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.

    Terminal
    git remote remove upstream
    Git Remote: Connect Your Repo to a Remote Server: the same workflow in Gitoryx
    In Gitoryx: Remotes and their branches appear directly in the commit graphHow it works
  6. Step 6: Change a remote URL

    If a repository moves, or you want to switch from HTTPS to SSH:

    Terminal
    git remote set-url origin git@github.com:user/new-location.git# Verify the change:git remote -v
  7. Step 7: Inspect a remote in detail

    git remote show gives you a full picture of a remote: its URL, all tracked branches, and which local branches are configured to push/pull from it.

    Terminal
    git 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 origin before pushing to an unfamiliar remote to confirm you're targeting the right branch.

  8. Step 8: Understand remote-tracking branches

    Remote-tracking branches like origin/main are local read-only snapshots of what the remote looked like the last time you fetched. They update only when you run git fetch or git 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 --all

    Tip: origin/main is NOT the same as main. It's a cached snapshot. Always git fetch before comparing branches.

  9. 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 prune cleans 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 true

    Careful: git remote prune only 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, origin is your copy, upstream is 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 -v before pushing or pulling.
Not fetching before checking remote tracking branches
origin/main is a local snapshot of the remote branch. It only updates when you fetch.
Fix: Run git fetch origin to 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 -u flag 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?
origin is 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, origin is your personal fork and upstream is the original repository you forked from. You push to origin (your fork) and pull updates from upstream (the source). This is a naming convention, not enforced by Git.
What is the difference between `git fetch` and `git pull`?
git fetch downloads new data from the remote and updates remote tracking branches (like origin/main) but does not change your local branch. git pull does 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) and upstream (the original project), or multiple deployment targets like origin, staging, and production.
How do I push to a remote for the first time?
Use git push -u origin <branch-name>. The -u flag sets the tracking relationship so future git push and git pull commands 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 run git fetch or git pull. Use git branch -r to list all remote-tracking branches.
How do I remove stale remote-tracking branches?
Run git remote prune origin to delete local references to remote branches that no longer exist. Use git fetch --prune to 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 with git remote -v.
All Git tutorials →
Gitoryx

Stop fighting Git. Start shipping.

Download the fast, native Git client that developers actually enjoy using.

v1.1.0 · macOS 12+ (Apple Silicon or Intel) · Windows 10+ · Linux x86_64