remote
git remote
Manages the set of named remote repositories your local repo tracks, such as origin or upstream. Lets you add, rename, remove, or inspect remote URLs.
git remote [<subcommand>] [<options>] Common flags
| Flag | Purpose |
|---|---|
| -v | Verbose: show fetch and push URLs |
| add <name> <url> | Register a new remote |
| remove <name> | Delete a remote and its tracking refs |
| rename <old> <new> | Rename a remote |
| set-url <name> <url> | Change a remote's URL |
| prune <name> | Delete stale remote-tracking branches |
Examples
git remote -v List all remotes with URLs
git remote add upstream https://github.com/org/repo.git Add an upstream remote for a fork
git remote set-url origin [email protected]:user/repo.git Switch origin from HTTPS to SSH
Gotcha
'set-url' with --push only changes the push URL, useful for read-mirror workflows; without it, both fetch and push are updated.
Related commands
git push
Uploads local commits from a branch to a remote repository, updating the remote-tracking references. Requires push permission on the remote.
git fetch
Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.
git clone
Downloads a repository from a remote URL into a new local directory, setting up the remote 'origin' automatically. Includes all commits, branches, and tags by default.