Why doesn't my Git status show me whether I'm up-to-date with my remote counterpart?

My guess at this point (I'm still waiting for git branch -vv or git rev-parse --symbolic-full-name "@{u}" results) is that you do not have origin/MyTestBranch set as the upstream for MyTestBranch.

To set a branch as the upstream for the current branch, use:

git branch --set-upstream-to upstream1

which in this case expands to:

git branch --set-upstream-to origin/MyTestBranch

To remove an upstream setting, use git branch --unset-upstream.

The presence or absence of an upstream setting mainly affects whether git status can tell you if you are ahead and/or behind, and whether git merge and git rebase can do their job with no additional parameters. So it's basically just a convenience setting.

Normally the upstream is set automatically when you first check out a branch by having git checkout create it based on a remote-tracking branch. For instance, on your first git clone, Git runs, at the end, the equivalent of:

git checkout master

even though you have no master yet. Git then discovers that you have origin/master (and no other remote/master so that there is no question as to which remote to use), and does the equivalent of:

git checkout -b master --track origin/master

which creates local master pointing to the same commit as remote-tracking branch origin/master, and setting origin/master as the upstream for master, all in One Big Do-What-I-Mean Fell Swoop.

When you create a new local branch and have not yet pushed it upstream, there is no origin/whatever remote-tracking branch for your local branch to track.2 In this case, you have to set the upstream manually, or use git push -u ...: the -u basically tells git push to run git branch --set-upstream-to for you (although it's actually all built in to the C code, at this point).


1If you're stuck with a truly ancient Git (pre-1.8.0) you must use git branch --set-upstream, which is tricky to get right, or git config, which is also tricky to get right. If at all possible, upgrade to a modern Git version.

2The set of words here—nouns like branch, nouns with adjectives like local branch and remote-tracking branch, and verbs like set-upstream-to and gerunds like tracking—is rather unfortunate. Git terminology, to put it in a nice short memorable Anglo-Saxon way instead of some polysyllabic neologistic phraseology, sucks rocks.3

3Or other Anglo-Saxon kick-ass word of choice.

Tags:

Git