A remote reference is a reference (pointer) to a remote repository, including branches, tags, and so on. You can git ls-remote (remote)
explicitly obtain a complete list of remote references, or by git remote show (remote)
obtaining more information about remote branches. However, a more common practice is to take advantage of remote trace branches.
The remote Trace branch is a reference to the remote branch state. They are local references that you can't move, and they move automatically when you do any network traffic.
They are named in (remote)/(branch) Form. For example, if you want to see the state of the master branch the last time you communicate with the remote repository origin, you can view the Origin/master branch. You work with coworkers to solve a problem and they push a iss53 branch, you may have your own local ISS53 branch, but the branch on the server points to the commit of origin/iss53.
This may be a bit difficult to understand, let's take a look at an example. Suppose you have a git server in git.ourcompany.com on your network. If you clone from here, the Git clone command automatically names it as Origin, pulls all its data, creates a pointer to its master branch, and names it locally as origin/master. Git will also give you a local master branch that points to the same place as the master branch of origin, so you have the basis for the job.
Remote Repository The name "origin", like the branch name "master", does not have any special meaning in Git. At the same time "master" is the git init
default starting branch name when you run it, because it is only widely used, "origin" is the git clone
default remote repository name when you run it. If you run git clone -o booyah
, then your default remote branch name will be booyah/master.
A Git clone will build your own local branch master and Remote Branch origin/master, and point them all to the Master branch on origin.
If you do some work at the local Master branch, but at the same time others push the commit to git.ourcompany.com and update its master branch, then your commit history will move in a different direction. Perhaps, as long as you are not connected to the origin server, your origin/master pointer will not move.
If you want to synchronize your work, run the git fetch origin
command. This command finds which server "origin" is (in this case, git.ourcompany.com), fetches data that is not locally, and updates the local database, moving the Origin/master pointer to the new, updated location.
To demonstrate that there are multiple remote warehouses and remote branches, we assume that you have another internal Git server that is used only for the development work of your sprint team. This server is located in git.team1.ourcompany.com. You can run the git remote add
command to add a new remote repository reference to the current project, which we'll explain in detail in Git basics. Name this remote repository as Teamone, as an abbreviation for the entire URL.
You can now run git fetch teamone to crawl data that is not available locally teamone the remote repository. Because the existing data on that server is a subset of the origin server, Git does not crawl the data but sets the remote trace branch teamone/master to the master branch of Teamone.