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.
Syntax
| Command | What it does |
|---|---|
git remote -v | List 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 upstream | Rename a remote |
git remote remove origin | Remove a remote |
git remote show origin | Show details about a remote |
Common cases
| Goal | Command |
|---|---|
| Connect a new repo to GitHub | git remote add origin <url> |
| Switch from HTTPS to SSH | git remote set-url origin git@github.com:... |
| Check what origin points to | git remote -v |
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.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.