AFAIK, git does the following when entering the following command:
"git push -u origin master":
- Git checks if master branch is located in remote repo. If not it will create it.
- Git determines the diff between the local branch and the remote branch. Git updates the "diff" in the remote branch.
- Git will also create a new REMOTE TRACKING branch in the local machine named "origin/master" to track the remote branch.
- Git will set the non-tracking branch named "master" to be a tracking branch (in order to track "origin/master").
This will cause 3 branches to exist:
- Tracking branch named "master" in my local machine (tracks origin/master).
- Remote tracking branch named "origin/master" in my local machine.
- Remote branch named "master" in remote repository"
Is this correct?
Re-edit: assume the master branch exist in local machine.
Thanks in advance.
Best How To :
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
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
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 (