Git Remote: Manage Remote Repositories

Learn how to add, remove, and manage git remote repositories. Work with upstream repos, multiple remotes, and forked project workflows.

git remote add upstream https://github.com/original/repo.git

Detailed Explanation

What Does git remote Do?

git remote manages the set of remote repositories your local repo communicates with. A remote is a named URL pointing to a copy of the repository hosted elsewhere (e.g., GitHub, GitLab).

Common Commands

# List remotes
git remote -v

# Add a remote
git remote add upstream https://github.com/original/repo.git

# Remove a remote
git remote remove upstream

# Rename a remote
git remote rename origin github

# Show detailed info about a remote
git remote show origin

The Fork Workflow

When you fork a repository, you typically have two remotes:

  • origin — your fork
  • upstream — the original repository
# Sync your fork with the original
git fetch upstream
git checkout main
git merge upstream/main
git push origin main

Changing a Remote URL

# Switch from HTTPS to SSH
git remote set-url origin git@github.com:user/repo.git

# Verify the change
git remote -v

Multiple Remotes

You can push to multiple remotes for redundancy or deployment:

git remote add deploy git@deploy-server:/var/repos/app.git
git push deploy main

Pruning Stale References

When remote branches are deleted, your local tracking references linger. Clean them up:

git remote prune origin
# or automatically during fetch:
git fetch --prune

Understanding remotes is fundamental to collaboration. Whether you are contributing to open source through forks or managing multiple deployment targets, git remote is the command that connects your local work to the wider world.

Use Case

An open-source contributor forks a repository and adds the original as an upstream remote so they can regularly sync their fork with the latest changes.

Try It — Git Command Builder

Open full tool