Remote tracking branches

Tracking or not tracking

When you clone a remote repository all the remote branches are tracked and set as upstream branch for the new checked out master, then git-pull(1) will appropriately merge from the starting point branch.

But it is not special to cloning, when a local branch is started off a remote-tracking branch, the remote branch is tracked, with the default value of the global branch.autosetupmerge configuration flag.

If you want to override this global setting, you can use the option --track or --no-track.

To start a local branch from origin/mywork but not track the origin, you issue:

git branch --no-track origin/mywork

Note that for two local branches the default, is no tracking, so with:

git branch develop master

or:

git checkout -b develop master

develop will not track master, unless you have used:

git branch --track  develop master

or:

git checkout -b --track  develop master

You can add a tracking of an upstream branch with:

git branch --set-upstream-to=origin/mywork mywork

This is specially usefull whan you first created mywork and then pushed it to origin as:

git push origin mywork

will not set origin/mywork as remote tracking branch for mywork, except if you explicitly issue:

git push --set-upstream origin mywork

or have set branch.autosetupmerge to always.

--set-upstream is abridged in -u.

Configuration of upstream branches

A branch is registered as upstream for another one by setting the two configuration variables branch.<name>.remote and branch.<name>.merge.

The previous tracking branch will result in a configuration including:

[branch "mywork"]
remote = origin
merge = refs/heads/mywork

[remote "origin"]
url = <url>
fetch = +refs/heads/*:refs/remotes/origin/*

see the documentation of these two configuration options in git-config(1) to learn the configuration setting a local branch as upstream for an other local branch.