Home·Terminal commands

git remote

git

Usage

git remote -v | git remote add <name> <url>

Manages the names and URLs of remote repositories; it only records them, so nothing travels until you actually fetch or push.

Common flags

FlagMeaning
-vlist the remotes with their URLs
add <name> <url>register another repository
set-url <name> <url>point an existing remote somewhere else
rename <old> <new>rename a remote
remove <name>forget a remote
show <name>branches it has and how they are tracked
prune <name>drop tracking refs for branches deleted there

Examples

git remote -v

shows the fetch and push URL of every remote

git remote add upstream https://github.com/orig/repo.git

adds the original repo alongside your fork

git remote set-url origin git@github.com:me/repo.git

switches origin from HTTPS to ssh

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git remote do?

Manages the names and URLs of remote repositories; it only records them, so nothing travels until you actually fetch or push.

Q. How do I type it?

git remote -v | git remote add <name> <url> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-remote