Information Technology Reference
In-Depth Information
you fetched and before you executed
$ git status -sb
or
$ git branch -a
-vv
.
Why tracking branches matter
You should have noticed that
$ git status -sb
always compares the local track-
ing branch and the remote tracking branch. This comparison is performed for your cur-
rent branch. To get the
[ahead N, behind M]
output of
$ git status -sb
,
you need to define the tracking for your current branch. If there are no
[branch"..."]
entries in your configuration file
.git/config
, such as:
[branch "master"]
remote = origin
merge = refs/heads/master
then git doesn't know which branches to compare. The output of
$ git status -
sb
would not contain
[ahead N, behind M]
information.
When you clone a repository, git automatically configures tracking for your
mas-
ter
branch. Git also sets the tracking when you pass to checkout command the name
of the remote branch—as
$ git checkout doc
in Recipe 5-2. Otherwise, you
have to set up tracking manually. Here are some different solutions to achieve it:
•
$ git branch --set-upstream-to=origin/master
com-
mand (as shown in the hint in Recipe 10-1)
•
$ git push -u origin master
command (as shown in the hint
in Recipe 10-2)
•
$ git config branch
commands (as shown in the hint in Recipe
10-1)
• Manually editing the
.git/config
file
Once set, the tracking information can be used to simplify many commands. If you
are currently on the
master
branch that was set to track the
origin/master
branch, then the three commands
$ git rebase
,
$ git rebase origin/
master
, and
$ git rebase origin/master master
are equivalent.
Basically, there are two reasons to define tracking branches: