Git - Notes24 Jun 2019
- remote repository
- upstream branch, tracking branch, remote-tracking branch
- name for the remote a project was originally cloned from
Checking out a local branch from a remote branch automatically creates what is called a “tracking branch” (or sometimes an “upstream branch”). Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git pull, Git automatically knows which server to fetch from and branch to merge into.
When you clone a repository, it generally automatically creates a master branch that tracks origin/master.
list all local branches and their upstream branches (if any):
$ git branch -vv
say, you create a new branch and push it into remote repository:
$ git checkout -b foo $ git push
NOTE: if remote repository is not specified, it defaults to
this is what happens as a result:
$ git branch -avv master d87ad32 [origin/master] misc * foo d87ad32 misc remotes/origin/master d87ad32 misc remotes/origin/foo d87ad32 misc
foois created in local repository
foois created in remote repository
origin/foois created in local repository
there 2 ways to set upstream:
for existing branch
$ git branch -u origin/foo > Branch 'foo' set up to track remote branch 'foo' from 'origin'.
for existing or new branch
$ git push -u
So you should supply -u flag on the first push. In fact, you can supply it on any later push, and it will set or change the upstream at that point.