Menu
CoddyTech

Git Remote

Last updated

git remote manages the shorthand names your repository uses for remote repositories - most commonly origin, pointing at your GitHub repo. You use it to add a remote when starting out, list the ones you have, rename or remove them, and change a remote's URL (for example switching from HTTPS to SSH).

Try these in the terminal playground - a real shell in your browser, nothing to install.

git remote manages the named connections - origin, upstream - between your local repository and its remotes.

Syntax

CommandWhat it does
git remote -vList remotes with their URLs
git remote add origin <url>Add a remote named origin
git remote set-url origin <url>Change a remote's URL
git remote rename origin upstreamRename a remote
git remote remove originRemove a remote
git remote show originShow details about a remote

Common cases

GoalCommand
Connect a new repo to GitHubgit remote add origin <url>
Switch from HTTPS to SSHgit remote set-url origin git@github.com:...
Check what origin points togit remote -v

Worked example

StepCommandResult
1git remote add origin https://github.com/you/app.gitRegisters the GitHub repository under the name origin
2git remote -vLists origin with its fetch and push URLs
3git push -u origin mainUploads main and sets it to track origin/main

Git remote FAQ

What is a Git remote?
A remote is a named reference to a repository hosted elsewhere - typically on GitHub, GitLab, or a server. The default name is origin. Remotes are what git push, git pull, and git fetch sync with. git remote is the command for managing those named references.
How do I add a remote?
Run git remote add origin <url>, using the repository's URL. This links your local repo to the remote under the name origin. Afterwards you can push with git push -u origin main. Use a different name (like upstream) if origin is already taken.
How do I change a remote's URL?
Use git remote set-url origin <new-url>. This is how you switch a repo from an HTTPS URL to an SSH one (or update it after a repo is renamed) without removing and re-adding the remote. Verify with git remote -v.
How do I see my remotes?
Run git remote -v to list every remote with its fetch and push URLs. For a detailed view of one remote - including its tracked branches - use git remote show origin.
What does git remote add origin do?
It saves a URL under the name origin in your repository's config. Nothing is uploaded or downloaded yet: the command only creates the name, so later you can type git push origin main instead of the full URL. If origin already exists, Git refuses with "remote origin already exists"; use git remote set-url origin <url> to point it somewhere else.
What is the difference between origin and upstream?
Both are only conventional names. origin is the remote you cloned from or pushed to first, usually your own copy. When you fork a project, the original repository is often added as a second remote called upstream with git remote add upstream <url>, so you can fetch its changes while pushing to your fork.
How do I fetch a branch from a remote?
Run git fetch origin to download every branch, then git switch <branch> to create a local branch that tracks origin/<branch>. The check out a remote branch page covers the variations.
Can I practice this online?
Yes. Open the terminal playground to run git remote in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers connecting to remotes step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED