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

← All Git commands · Git cheat sheet · Git rebase vs merge