Remote Configuration

Keeping track of all of the information about a remote repository reference can become tedious and difficult: you have to remember the full URL for the repository; you must type and retype remote references and refspecs on the command line each time you want to fetch updates; you have to reconstruct the branch mappings; and so on. Repeating the information is also likely to be quite error-prone.

You might also wonder how Git remembers the URL for the remote from the initial clone for use in subsequent fetch or push operations using origin.

Git provides three mechanisms for setting up and maintaining information about remotes: the git remote command, the git config command, and editing the .git/config file directly. All three mechanisms ultimately result in configuration information being recorded in the .git/config file.

git remote

The git remote command is a more specialized interface, specific to remotes, that manipulates the configuration file data. It has several subcommands with fairly intuitive names. There is no “help” option, but you can circumvent that to display a message with subcommand names via the “unknown subcommand trick”:

$ git remote xyzzy
error: Unknown subcommand: xyzzy
usage: git remote
   or: git remote add <name> <url>
   or: git remote rm <name>
   or: git remote show <name>
   or: git remote prune <name>
   or: git remote update [group]

    -v, --verbose         be verbose

You saw the git remote add and update commands in Make Your Own origin Remote, and show ...

Get Version Control with Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.