I am learning Git and am attempting to understand the difference between \"tracking\" a remote and defining an \"upstream\" relationship with it (with the -u
tag).
git push origin master
explicitly says "push the local branch 'master' to the remote named 'origin'". This does not define a persistent relationship, it just executes a push this one time. Note that the remote branch is assumed to be named "master".
git push -u origin master
is the same thing, except it first adds a persistent tracking relationship between your local branch "master" and the remote named "origin". As before, it is assumed the remote branch is named "master".
If you have done a push with -u
already, then the relationship is already defined. In the future, you can simply say git push
or git pull
, and git will automatically use the defined remote tracking branch without being told explicitly.
You can view your tracking relationships with git branch -vv
, which will list your local branches along with their current HEAD commit and, if one is set, the remote tracking branch. Here is an example.
$ git branch -vv
* master 58a0d68 [origin/master] Fix CSS regression bug
migration_tool 2a24ff7 [origin/migration_tool] [#906] Fix table layout problem
topic-ajax-timeouts fe854f2 Adjust timeouts to be more realistic
Here are shown 3 branches along with their current HEAD commits and commit messages. On the first two, there is a tracking branch specified, but the third branch is not tracking a remote branch.