SVN uses a single, centralized repository to serve as a communication hub for developers, and collaboration takes place by passing changesets between developers’ working copies and the central repository. This is different from Git’s distributed collaboration model, which gives each developer their own copy of the repository, complete with their own local history and branch structure. Typically, users need to share a series of commits instead of a single change set. Instead of committing a change set from a working copy to the central repository, Git allows you to share entire branches between repositories.
The git remote command is a piece of the broader system that is responsible for synchronizing changes. Logs logged through the git remote command are used in conjunction with the git fetch, git push, and git pull commands. All of these commands have their own synchronization responsibilities that can be explored in the corresponding links.
The git remote command allows you to create, view, and delete connections to other repositories. Remote connections are more like bookmarks than direct links to other repositories. Instead of providing real-time access to another repository, they serve as convenient names that can be used to reference a not-so-convenient URL.
For example, the following diagram shows two remote connections from the repository to the central repository and to another developer’s repository. Instead of referring to them by their full URLs, you can pass the origin and john shortcuts to other Git commands.
Overview of remote use of Git
The git remote
command is essentially an interface for managing a list of remote entries that are stored in the repository’s ./.git/config file. The following commands are used to view the current status of the remote list.
Viewing git remote configurations
List the remote connections you have to other repositories
Same as the previous command, but include the URL of each connection
Creating and modifying remote git configurations
The git remote command is also a convenient method or ‘helper’ to modify the ./ file.
/config of a repository. The commands below allow you to manage connections to other repositories. The following commands will modify the /.git/config file in the repository. The output of the following commands can also be achieved by directly editing the ./.git/config file with a text editor.
Create a new connection to a remote repository. After you add a remote control, you can use it as a convenient shortcut for in other Git commands
. Delete the connection to
the remote repository named
Rename a remote connection from to
Remote discussion of
Git is designed to give every developer a completely isolated development environment. This means that information is not automatically passed from one repository to another. Instead, developers must manually pull the upstream commits to their local repository or manually push their local commits to the central repository. The git remote command is actually an easier way to pass URLs to these “share” commands.
The remote source
When you clone a repository with git clone, it automatically creates a remote connection named origin that points to the cloned repository. This is useful for developers creating a local copy of a central repository, as it provides an easy way to pull upstream changes or publish local commits. This behavior is also why most Git-based projects call their source a central repository.
Git supports many ways to reference a remote repository. Two of the easiest ways to access a remote repository are through the HTTP and SSH protocols. HTTP is an easy way to allow anonymous read-only access to a repository. For example:
But, it’s generally not possible to send acknowledgments to an HTTP address (you don’t want to allow anonymous inserts anyway). For read and write
access, you need to use SSH instead
: you’ll need a valid SSH account on the host machine, but other than that, Git supports authenticated access via out-of-the-box SSH. Modern and secure 3rd party hosting solutions like Bitbucket.com will provide you with these URLs.
commands The git remote command is one of many Git commands that takes additional ‘subcommands’ appended. Below is an examination of commonly used git remote subcommands.
Add a record to ./.git/config for the remote name in the repository url. Accepts a -f option, which will search for git immediately
after creating the remote registry. Accepts a -tags option, which will immediately search
for and import all tags from the remote
. Update ./.
git/config to rename the record to . All remote monitoring branches and remote control configuration settings are updated.
git/config and removes the remote control named . All remote tracking branches and remote control configuration settings are removed.
Generates the URLs of a remote record.
Accept -push, push URLs are queried instead of retrieval URLs.
With -all, all URLs of the remote control will be listed.
Generates high-level information about the remote.
Deletes local branches that are not present in the remote repository
It accepts a -dry-run option that will list which branches are set up to be pruned, but will not actually prune them
Remote Git examples
In addition to
source, it’s often convenient to have a connection to your teammates’ repositories. For example, if your coworker, John, maintained a publicly accessible repository on dev.example.com/john.git, you could add a connection as follows:
Having this kind of access to individual developer repositories makes it possible to collaborate outside of the central repository. This can be very useful for small teams working on a large project.
Show remote controls By
default, the git remote command will list previously stored remote connections to other repositories. This will produce a single-line output that lists the “bookmark” name names of the remote repositories.
Invoking git remote with the -v option will print the list of flagged repository names and the URL of the corresponding repository. The -v option stands for “detailed.” Below is an example of detailed git remote output output.
Add remote repositories
The git remote add command will create a new connection record to a remote repository. After you add a remote, you’ll be able to use it as a convenient shortcut for other Git commands. For more information about accepted URL syntax, see the “Repository URLs” section below. This command will create a new record within the ./.git/config of the repository. The following is an example of this configuration file update
a remote control
The show subcommand can be added to git remote to provide detailed results about configuring a remote control. This output will contain a list of branches associated with the remote control and also the connected endpoints to get and send.
Getting and pulling Git remotes
Once a remote registry has been configured by using the git remote command, the remote name can be passed as an argument to other Git commands to communicate with the remote repository. Both git fetch and git pull can be used to read from a remote repository. Both commands have different operations that are explained in greater depth in their respective links.
remote controls The git push command is used to
write to a
This example will upload the local state of to the remote repository specified by
Renaming and deleting remote controls
The git remote rename command is self-explanatory. When run, this command will rename a remote connection from to . Also, this will modify the contents of ./.git/config to rename the registry for remote control there as well.
The git remote rm command will remove the connection to the remote repository specified by the parameter. To demonstrate this, let’s “undo” the remote addition of our last example. If we run git remote rm remote_test, and then examine the contents of ./.git/config we can see that the [remote “remote_test”] registry is no longer there.