Remote Git Repositories | git remote
The git remote command
git remote creates, inspects, renames, and removes connections to other repositories. A remote connection is more like a bookmark than a direct live link to another repository. Instead of accessing another repository in real time, it works as a short name that can be used in place of a long URL.
For example, a local repository can have one remote connection to a central repository and another remote connection to another developer’s repository. Instead of referring to them by full URL, you can pass shortcut names such as origin and john to other Git commands.
Git Tutorial: git remote
Usage
git remote
Lists remote connections to other repositories.
git remote -v
Similar to the command above, but also displays the URL for each connection.
git remote add <name> <url>
Creates a new connection to a remote repository. After it is created, <name> can be used as a shortcut for <url> in other Git commands.
git remote rm <name>
Removes the connection to the remote repository named <name>.
git remote rename <old-name> <new-name>
Renames a remote connection from <old-name> to <new-name>.
Additional notes
Git is designed to provide each developer with an independent development environment. Because of that, information does not automatically move between repositories. Developers need to manually fetch commits from a central repository into their local repository, or manually push local commits back to the central repository. git remote provides a convenient way to pass repository URLs to those sharing commands.
The origin remote
When you clone a repository with git clone, Git automatically creates a remote connection named origin that points back to the cloned repository. This gives developers an easy way to pull upstream changes or publish local commits. In most Git-based projects, the central repository is named origin.
Repository URLs
Git supports many ways to refer to remote repositories. HTTP and SSH are common ways to access remote repositories. HTTP is a simple way to provide anonymous read-only access:
http://host/path/to/repo.git
In general, however, you cannot push to an HTTP address anonymously. For read-write access, use SSH:
ssh://user@host/path/to/repo.git
This requires a valid SSH account on the host machine. Apart from that, Git supports authenticated access by default.
Example
In addition to origin, it is often useful to create connections to other developers’ repositories. For example, if your colleague John has a public repository at dev.example.com/john.git, create a connection as follows:
git remote add john http://dev.example.com/john.git
Accessing individual developers’ repositories this way enables collaboration without going through the central repository. This is especially useful for small teams working on large projects.