Git remote: description, operation, reposition

The popular Git version control system gives each developer their own copy of the reposition of the project or repository, that is, the repository, complete with its local history and structure. In Git terminology, such a repository is called local. Remote repositories or git remote repositories are local copies, but stored elsewhere on the Internet. Such storage can serve as a backup for those cases, if something happens to the computer, as well as for collaboration.

remote branches




Remote access and its features

Team work on a project is impossible without learning how to manage remote repositories. Each project modification is stored on the Web or on a server of a version control system such as Git. There may be several options for a project with slight differences, and all of them are available to other developers. Some repositories can only be viewed; others are allowed to make changes. For each such action in the Git system, there are several special commands that allow you to manage remote copies of projects. All of them are a modification of the main command - git remote.

Git Remote Repository Management

The following describes the process of working with remote repositories in Git. Typically, system users have to share a number of commits, rather than a single set of changes. Instead of pushing a set of changes from a working copy to a central repository, Git allows developers to exchange whole branches between separate repositories. Each user can have several repositories, each of which is usually read-only or read-write. Collaboration with others involves managing these remote repositories. For this, we need a command for remote access - git remote. It is part of the broader system responsible for synchronizing changes.





git remote branches




Remote Access Features

Entries registered with the remote access command are used in conjunction with the git remote push, fetch, and pull commands. Both git fetch and git pull can be used to read from a remote repository. The git remote command allows you to create, view, and delete connections to other repositories. For example, push is used to put data in storage, and pull, on the contrary, to receive. The fetch command is needed to extract all the information that is not on the local copy from the remote repository. After its execution, links are created to all new branches in which the missing data is located. That is, updates do not merge with the current project, but are located separately.

git remote




Subsequently, the data will need to be drained manually if the need arises. To automatically retrieve and connect repositories, use git remote pull. Remote connections are more like bookmarks than direct links to other repositories. Instead of providing real-time access, they serve as convenient names that can be used to link to not-so-convenient URLs.





The remote access command is essentially an interface for managing the list of records that are in the ./.git/config file. It is needed to manage remote repositories, delete nonexistent ones, track certain branches and change the addresses of remote repositories (git change remote).

Mapping Remote Storage

By default, Git deletes a list of previously saved remote connections to other repositories. This creates a line in which the names of the remote repositories will be indicated. A git remote call with the -v option will show a list of repository bookmark names and, in addition, their corresponding URLs. The -v option means verbose. The git remote add command will create a new connection entry in the remote repository. After the remote entry has been configured using the remote access command, its name can be transferred to other Git commands to communicate with the repository.

Remote Access Command Configuration

The following are options for using the command to manage repositories. A simple git remote entry lists the remote connections. There are several configurations. The command is convenient for making changes to the ./.git/config file. It can also be edited manually using a text editor. The Git remote access command is one of those that accepts additional “subcommands.”

git push remote




Options for “subcommands”:

  1. The “git remote add <name> <url>" command is used to create a new connection to the remote repository. After adding remote control, it becomes possible to use <name> as a convenient shortcut for <URL> in other commands. This subcommand accepts the -f option, which adds the branch name immediately after creating the remote entry. As well as the --tags option, which immediately extracts <name> and imports each tag from the remote repository.
  2. Another git remote rm <name> command allows you to delete a connection to a remote repository. It modifies /.git/config and deletes a file named <name>. If you then run this command with the remote_test prefix, you can see that the record no longer exists.
  3. The git remote rename <old-name> <new-name> entry renames the remote connection. In this case, the old name is indicated first, and then the new one. To change the remote repository URL, you must update the configuration file with the new URL. Otherwise, you will receive an error message.
  4. The get-url <name> command prints out URLs for remote access. Adding the - all option will list all the URLs of the available remote repositories.
git remote origin




Remote Repository Links

Git supports many ways to link to a remote repository. The two simplest ones are: accessing the remote repository through HTTP and through SSH protocols.

HTTP is the easiest way to allow read-only anonymous access. But in the first case, it is not possible to make changes to the project via HTTP. For access where read and write is possible, you need to use SSH. This will require a valid SSH account. In addition, Git supports authentication with SSH.

Features repository cloning: git remote origin

Git is designed to create a completely isolated environment for every programmer for a project. This means that information is not automatically communicated between repositories. Instead, developers should manually push the changes to the local repository and send their commits back to the central repository. Therefore, the git remote command is an easy way to pass a URL for sharing information.

When a developer clones a repository using git clone, he automatically creates a remote connection with him. When cloning, Git by default names the central repository - origin, so the command to access it is written as git remote origin. This feature is useful for those who create a local copy of the central repository, since it will make it easier to publish commits and save changes.

git change remote




Work with branches remotely

Sometimes you need to find out which branches exist in the remote repository. If you use GitHub or Gitweb to host your repository, it is usually easy to determine their names. But there are times when they are not available. You can also manage individual branches using the git remote branches command.

Remote branch tracking is written as: <remote repository name> / <branch>. For example, to display the master branch on your origin server the last time you access it, you need to check the origin / master branch. If in the process of cooperation with another developer, he uploads the updated project with a new branch, then on the server it will be presented as a link indicating the commit named by the name of this branch.




All Articles