Git/
Lesson

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  tracked

This command shows you which local branches are linked to which remote branches.

02

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.git

After 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.git
AI pitfall
When you ask AI how to contribute to an open-source project, it often skips the upstream 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.
03

Common remote names

NameTypical usage
originYour fork or main repository (always present)
upstreamThe original repository when you forked
backupA secondary backup copy
deployDeployment server
gitlab / githubWhen mirroring across platforms
04

Remove and rename remotes

# Remove a remote
git remote remove origin

# Rename a remote
git remote rename origin github
05

Change 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 -v
06

Sync 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 main

Now your fork is up to date with the original.

07

Quick reference

CommandAction
git remoteList remote names
git remote -vList remotes with URLs
git remote show nameDetails on a specific remote
git remote add name urlAdd a new remote
git remote remove nameRemove a remote
git remote rename old newRename a remote
git remote set-url name urlChange a remote URL
git fetch --allFetch from all remotes