What is the purpose of "git push
AFAIK, git does the following when entering the following command:
"git push -u origin master":
This will cause 3 branches to exist:
Is this correct?
Re-edit: assume the master branch exist in local machine.
Thanks in advance.
The master
branch must exist before pushing.
That means at least one commit must have been done in a newly created repo (as I explained in "Why do I need to explicitly push a new branch?").
The remote tracking branch origin/master
and the master branch on the remote upstream repo are then created.
To your point 4 (since master already exist), what is created is the association between the local branch master
and an upstream branch (hence the -u
or --upstream-to
option) origin/master
in .gitconfig
:
[branch "master"]
remote = origin
merge = refs/heads/master
From the discussion:
So If I can have master
branch to track directly a remote branch, what benefit do I get in having:
" master
" points to " origin/master
" points to "remote master
"?
What benefit I get in having this extra middleman branch?
You can indeed push directly to a remote branch with git push https://<login>@github.com/<login>/<repo> master:master.
The benefit of establishing formally a tracking relationship between a local branch master
and a remote tracking one ( origin/master
) is to record where to push to ( git push
) or from where to merge from ( git pull
).
上一篇: 分支与Git中的新项目
下一篇: “git push的目的是什么?