Git Remote
In short
A Git remote is a named shortcut, such as origin, to another copy of your repository, usually on a server, that you push commits to and pull commits from.
What is a Git remote?
A Git remote is a bookmark your local repository keeps for another copy of the same project, usually hosted on a server or a code hosting platform. Each remote has a short name and a URL, so instead of typing the full address every time you can write git push origin main. It works like a contact in your phone: you save the name once and never type the full number again.
When you clone a repository, Git automatically adds a remote named origin that points to the URL you cloned from. You manage remotes with the git remote command: git remote -v lists them, git remote add creates one, and git remote set-url changes an address, for example when switching from HTTPS to SSH. The names and URLs are stored in the repository's .git/config file.
Remotes are how separate copies of a distributed repository stay in sync. After a git fetch, Git keeps read-only remote-tracking branches such as origin/main, which record where each branch was on the remote the last time you checked, so you can compare them with your local branches. A repository can have several remotes, and forked projects commonly use two: origin for your fork and upstream for the original project.
People often say 'the remote' to mean the remote repository itself, which is fine in conversation, but strictly the remote is only your local name and URL for it. Likewise, a remote-tracking branch such as origin/main is your local, possibly outdated, snapshot of a branch on that server, which is why git status can report 'up to date with origin/main' after teammates have already pushed new work. A remote is also different from a fork, which is a full copy of a repository on a hosting platform; your fork is simply one of the places a remote can point to.
Key takeaways
- A remote is a short name, such as
origin, paired with the URL of another copy of the repository. git clonecreates theoriginremote automatically.git remote -vlists remotes, andgit remote addcreates a new one.- Remote-tracking branches like
origin/mainshow where the remote's branches were at the last fetch. - Forked projects often use
originfor the fork andupstreamfor the original.
Example
# List remotes with their URLs
git remote -v
# origin https://github.com/your-name/project.git (fetch)
# origin https://github.com/your-name/project.git (push)
# Add the original project as a second remote
git remote add upstream https://github.com/original-owner/project.git
# Switch origin from HTTPS to SSH
git remote set-url origin git@github.com:your-name/project.git
# Download new commits from a remote and see what you're missing
git fetch upstream
git log --oneline main..upstream/mainReaders ask
What does origin mean in Git?
origin is the default name Git gives the remote you cloned from. It is only a convention, so you can rename it with git remote rename or add other remotes with different names.
What is the difference between origin and upstream?
origin usually points to your own copy of the repository, such as your fork, while upstream is the conventional name for the original project you forked from. Both are ordinary remotes; only the names differ.
How do I change a remote's URL?
Run git remote set-url <name> <new-url>, for example git remote set-url origin git@github.com:your-name/project.git. Check the result with git remote -v.
See also
- RepositoryVersion Control, p. 34A repository is the storage location for a project, holding all of its files plus the complete history of every change recorded by a version control system.
- Git CloneVersion Control, p. 13Git clone is a Git command that downloads a complete copy of an existing repository, including its full history, and sets it up on your computer for work.
- Git PushVersion Control, p. 18Git push is a Git command that uploads your local commits to a remote repository, updating the matching branch there so others can see and use your work.
- Git PullVersion Control, p. 17Git pull is a Git command that downloads new commits from a remote repository and immediately integrates them into your current local branch.
- ForkVersion Control, p. 9A fork is a personal copy of someone else's repository on a hosting platform, letting you experiment freely and propose changes back to the original project.
- BranchVersion Control, p. 2A branch in Git is an independent line of development that lets you work on a feature or fix in isolation, without affecting the main code until you merge it.
- Git FetchVersion Control, p. 15git fetch downloads new commits, branches and tags from a remote and updates remote-tracking branches like origin/main but not your own branches or files.
Spotted a mistake or something missing on this page?Suggest an edit