Add, rename, prune, set URLs.
git remote manages the named URLs your repo talks to. Without it, fetch and push have nowhere to go.
A remote is just a named bookmark to another repo's URL plus a refspec. origin is convention, not magic — you can have as many remotes as you want, each with its own fetch/push URL.
git remote [-v]
git remote add [-t <branch>] [--mirror=fetch|push] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-url [--push] <name> <newurl>
git remote show <name>
git remote prune <name>| Flag | What it does |
|---|---|
-v / --verbose | Show URLs alongside names. Use this always — bare git remote is nearly useless. |
--track <branch> | On add, restrict the fetch refspec to one branch instead of all. |
--mirror=fetch | Fetch maps refs exactly — including remote-tracking and tags. Useful for backup mirrors. |
--mirror=push | ⚠️ Push deletes refs on the remote that don't exist locally. Destructive — only for true mirrors. |
-f | On add, fetch immediately after adding. Saves a step. |
--no-tags / --tags | On add, control whether tag auto-following happens. |
git remote add upstream https://github.com/torvalds/linux.gitgit remote rename origin githubgit remote remove old-fork--push sets only the push URL.git remote set-url origin git@github.com:me/repo.gitgit remote set-head origin --autogit remote show origingit remote prune origingit remote update --prune-v.git remote get-url --push originorigin is your fork, upstream is the canonical repo.set-url, then push).--mirror=push to a backup server on a cron.prune.git remote add upstream https://github.com/owner/repo.gitgit remote set-url origin git@github.com:owner/repo.gitgit remote show origingit remote update --pruneorigin for your fork and upstream for the source. Don't invent novel naming — readers expect this.git remote prune origin (or set fetch.prune=true) to keep git branch -r honest.--mirror=push will delete remote branches that don't exist locally. People lose work this way.set-url does not update the push URL unless you pass --push. Triple-URL setups confuse everyone..git/config; custom refspecs you hand-edited may not survive cleanly.Hit each option, then Check answers. Score is recorded; Next is always open.