0

I read What is a tracking branch? and I am not sure wchich exactly master or origin/master is tracking branch or maybe both of them are

karol wołonciej
  • 109
  • 1
  • 1
  • 10

2 Answers2

1

master is a local branch.

origin/master is a remote-tracking branch.

A tracking branch is a local branch associated with another branch (usually a remote-tracking branch). Operations like git status, when reporting on the tracking branch, will indicate whether the branch is ahead of or behind the branch it tracks.

When you clone a repository, master is usually created as a tracking branch associated with origin/master, which itself is the branch master on the remote repository named origin.

chepner
  • 497,756
  • 71
  • 530
  • 681
0

The word tracking, in Git, is badly overloaded—perhaps worse than the word branch, or perhaps just about the same.

The Git documentation uses the phrase remote-tracking branch name to describe names like origin/master. Note that this phrase literally requires all four words in it, but because humans are humans, they tend to shorten it to remote-tracking branch. I like to shorten it to remote-tracking name because it is not a branch name in one very important sense.1

Note that this phrase uses the word tracking as an adjective.2 The verb form, to track, is also used with branches: we say that a branch name such as master tracks the name origin/master if the name origin/master is set as the upstream of the name master. Each (local) branch name can have one upstream set. That is, a branch either has an upstream–e.g., master typically has origin/master as its upstream—or it has no upstream at all. Having an upstream makes some Git operations more convenient or pleasant.

Meanwhile, master is a branch name. We (and Git) sometimes use the phrase local branch to emphasize that this branch name is specific to this one particular Git repository. The word branch in Git is, however, ambiguous: see What exactly do we mean by "branch"?

I strongly dislike the shortened phrase tracking branch because it's incredibly unclear whether someone is saying tracking branch as shorthand for a remote-tracking name (origin/master), or as shorthand for setting the upstream of a branch (setting master to "track" origin/master). Or, as chepner notes, it can be used to refer to a branch that has such an upstream! I recommend avoiding this phrase.

Finally, it's worth mentioning that the verb form of track is also used with file names. File README.md is tracked if that file's name is in Git's index.

The index itself actually has three names: index, which is the one I just used, but also staging area and—rarely these days—cache. You didn't ask about the index, but it's worth mentioning because any file that is in the index is a tracked file, which is another way the word track is used.


1In particular, git checkout origin/master puts you in detached HEAD mode, because origin/master is not a branch name.

2Technically this is a gerund (a verb being used as a noun) that is being modified to become an adjective. The same verb can, in other circumstances, be a present participle. See, e.g., https://medium.com/@engtuto1/can-gerunds-be-also-used-as-adjectives-89e5698411f3

torek
  • 448,244
  • 59
  • 642
  • 775