Information Technology Reference
In-Depth Information
The refspec ensures that the remote
master
branch will be copied into the local
.git/refs/remotes/origin/master
file. After the fetch command, the
.git/objects
directory in the local repository contains the objects copied from the
remote repository. You should notice that the
$ git fetch
command creates a local
file
.git/refs/remotes/origin/master
. This is a copy of a remote branch.
The copy is stored in a local repository as a remote tracking branch. Back in Recipe 5-2
I emphasized that the remote tracking branch is a local branch. This is how remote
tracking branches are created: they appear in your repository after the
$ git fetch
command. You can verify this with a
$ git branch -a -vv
command issued
right after
$ git fetch
. Even if you remove a remote tracking branch with a
$
git branch -d -r
command, it will be recreated after the next
$ git fetch
command.
The next step is to set up a local
master
branch. As you already know an ordinary
local branch is just a text file storing the appropriate SHA-1 name. We want our branch
to point to the same revision as the
.git/refs/remotes/origin/master
branch created during fetch operation. The branch stored in
.git/refs/remotes/
origin/master
can be referred to as
origin/master
. How do you find the
SHA-1 name of the revision pointed by some symbolic reference
origin/master
?
We can use the $
git rev-parse
command for this purpose. Run the command
$
git rev-parse origin/master
. It will print the SHA-1 name of the revision
pointed by the
.git/refs/remotes/origin/master
branch. To create an or-
dinary local branch pointing to the same revision it is sufficient to store the SHA-1 in a
text file:
$ git rev-parse origin/master > .git/refs/heads/master
Hint
The result of the
$ git rev-parse origin/master > .git/
refs/heads/master
command can also be achieved with the
$ cp .git/
refs/remotes/origin/master .git/refs/heads/master
command.
The above command creates an ordinary local branch named
master
. The output
of the
$ git branch -a -vv
command should be similar to:
* master 60478cc Bump version to 0.3.1
remotes/origin/master 60478cc Bump version to 0.3.1