Managing remotes is like managing contacts in your phone, you can have several, name them as you want, and update them when their address changes. The difference is that these "contacts" are Git repositories that can receive or send code.
View your remotes
First step: know what you are connected to.
# Simple list of names
git remote
# origin
# upstream
# Detailed list with URLs
git remote -v
# origin https://github.com/my-user/my-project.git (fetch)
# origin https://github.com/my-user/my-project.git (push)
# upstream https://github.com/original/project.git (fetch)
# upstream https://github.com/original/project.git (push)The suffix (fetch) indicates the URL for retrieving changes. (push) is the URL for sending your changes. Generally, they are the same.
Inspect a remote in detail
git remote show origin
# * remote origin
# Fetch URL: https://github.com/user/repo.git
# Push URL: https://github.com/user/repo.git
# HEAD branch: main
# Remote branches:
# main tracked
# feature-login trackedThis command shows you which local branches are linked to which remote branches.
Add a remote
When you start a project locally and want to connect it to a server:
git remote add origin https://github.com/user/my-project.gitAfter this command, origin points to your GitHub repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.. You can now push and pull.
The forkWhat is fork?A personal copy of someone else's repository on a platform like GitHub, letting you make changes freely and propose them back via pull request. workflow: two remotes
When contributing to open source, you need two remotes:
# 1. Clone your fork (automatically creates 'origin')
git clone https://github.com/YOUR-USERNAME/react.git
cd react
# 2. Add the original project as 'upstream'
git remote add upstream https://github.com/facebook/react.git
# 3. Verify
git remote -v
# origin https://github.com/YOUR-USERNAME/react.git
# upstream https://github.com/facebook/react.gitupstream setup. It will tell you to clone the original repo directly. That works for reading the code, but you cannot push to someone else's repository. Always fork first, clone your fork, and add the original as upstream.Common remote names
| Name | Typical usage |
|---|---|
| origin | Your fork or main repository (always present) |
| upstream | The original repository when you forked |
| backup | A secondary backup copy |
| deploy | Deployment server |
| gitlab / github | When mirroring across platforms |
Remove and rename remotes
# Remove a remote
git remote remove origin
# Rename a remote
git remote rename origin githubChange a remote URL
URLs change, platform migrations, account renaming, HTTPSWhat is https?HTTP with encryption added, so data traveling between your browser and a server can't be read or tampered with by anyone in between. to SSH switch:
# Switch from HTTPS to SSH
git remote set-url origin git@github.com:user/repo.git
# Verify the change
git remote -vSync your forkWhat is fork?A personal copy of someone else's repository on a platform like GitHub, letting you make changes freely and propose them back via pull request. with upstream
Classic workflow for open source contributors:
# 1. Retrieve changes from the original project
git fetch upstream
# 2. Go to your local main branch
git checkout main
# 3. Merge upstream changes into your branch
git merge upstream/main
# 4. Push to your fork
git push origin mainNow your fork is up to date with the original.
Quick reference
| Command | Action |
|---|---|
git remote | List remote names |
git remote -v | List remotes with URLs |
git remote show name | Details on a specific remote |
git remote add name url | Add a new remote |
git remote remove name | Remove a remote |
git remote rename old new | Rename a remote |
git remote set-url name url | Change a remote URL |
git fetch --all | Fetch from all remotes |