Information Technology Reference
In-Depth Information
When you issue the commands:
$ git checkout -b foo master
$ git checkout -b bar master
they create two
ordinary local branches
named
foo
and
bar
. To be sure, no one uses
the adjective “ordinary.” I've just invented it in the “spur of the moment” to make all
the types of branches clear to you. They are usually referred to as local branches. But
let's stick with this terminology for a while—it will help to avoid confusion.
Remote tracking branches
are local copies of remote branches. They preserve the
state of remote branches as it was during the initial clone or last fetch operation. The
point of creating remote tracking branches is very simple: whenever you want to check
the state of remote branch you should consult a remote tracking branch. The remote
tracking branches are named
remotes/X/Y
, where
X
represents the alias of a remote
repository and
Y
is the name of the remote branch. For a remote branch named
lorem
stored in the remote repository
05-01
aliased as
origin
the remote tracking branch
would be named
remotes/origin/lorem
. This name can be simplified to
ori-
gin/lorem
. The remote tracking branches are stored in a packed format; therefore
you will not find them in the
refs/remotes/origin
directory. They are stored in
the
.git/packed-refs
file. You can treat the remote tracking branches as read
only—we will not commit in them.
Local tracking branches
are used to publish your commits in a remote branch.
They are similar to ordinary local branches: you can commit in them. When in loose
format they are stored in
.git/refs/heads
directory, for example. The main dif-
ference is that they are connected to remote tracking branches. Every local tracking
branch tracks one of the remote tracking branches. Initially, they point to exactly the
same revisions as the remote tracking branches. .
Local branches are listed with the
$ git branch
command. The command
prints both local tracking branches and ordinary local branches. To list remote tracking
branches use the
-r
parameter
$ git branch -r
. You can list all the branches us-
ing
$ git branch -a
command. The additional parameter
-v
prints the latest re-
vision in every branch. If you want to get the full classification into three groups, or-
dinary local branches, remote tracking branches, and local tracking branches, use the
parameter
-vv
.
All four types of branches are depicted in
Figure 5-7
. The properties of the three
branches
info
,
origin/info
, and
foo
from the repository
05-02
are summar-
ized in
Table 5-1
.