What is a git upstream
In the command
git push -u origin master
The -u
flag means that your local branch will become a tracking branch. That is, a branch that tracks a remote branch (the "upstream" branch), so that future git pull
will know which branch to merge from and git push
will be directed to the correct remote branch.
origin
is the remote repository you are pushing to.
master
is the refspec parameter. The refspec parameter specifies which local branch is pushed to what remote branch. It can be complicated, but in this case the short form master
means to push the local master
branch to the remote branch with the same name, origin/master
.
Technically, the tracking adds the following information about the master
branch to your .git/config
:
[branch "master"]
remote = origin
merge = refs/heads/master
and it creates a file here .git/refs/remotes/origin/master
, representing the remote branch.
"Upstream" is the repo you cloned (some of) the branches in yours from, and where you push changes to those branches (and optionally entire new branches) once they've been committed. GitHub acts as your upstream because they store the revisions for you, in a centralized location.