When you have created a github-repo and added the the github-repo as remote
git remote add origin https://github.com/githubname/reponame.git
then you need to push your first commit with
git push -u origin master
I read (Why do I need to do `--set-upstream` all the time?) that this a short form for doing
git branch --set-upstream-to my_branch origin/my_branch git push
What is a upstream exactly and why do I need to set it? There is little information about this on the net. I know that there is a similar topic What does 'git remote add upstream' help achieve?, but in my opinion it does not explain exactly what the upstream is and what git push -u origin master
does, especially what is origin master
pointing to, is it the local repo or the remote repo?
Generally speaking, upstream is where you cloned from (the origin). Downstream is any project that integrates your work with other works. The terms are not restricted to Git repositories.
upstream generally refers to the original repo that you have forked. (see also "Definition of “ downstream ” and “ upstream ”" for more on upstream term) origin is your fork: your own repo on GitHub, clone of the original repo of GitHub.
If your push. default is set to simple or upstream , the upstream setting will make git push , used with no additional arguments, just work.
Steam is a video game digital distribution platform developed by Valve and Origin is a video game digital distribution platform developed by EA. Comparing the two platforms, most gamers prefer Steam to Origin.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With