The first thing to make clear is that the git operation revolves around 3 big steps (virtually all SCM)
1. Fetching data from Git (git clone)
2. Change the Code
3. Transfer the changes back to Git (git push)
These 3 steps involve two repository, one is the remote repository, and the other one is the local repository, and then the workspace. which
1, 32 steps related to remote Server/remote repository/remote branch,
2 related to local repository/local branch. git clone will copy a copy to your local, Git push, based on the remote Server/repository/branch you specify, and your changes to all files are done locally in your local repository, and your changes ( Local branch) and remote branch are independent (parallel). GITK shows the local repository.
After clone is complete, Git will automatically name this remote Repository as origin (origin is just an alias, run Git remote–v or view. Git/config can see the meaning of origin) and download all of the data, Create a pointer to its master branch, we represent the remote branch in the form of (remote warehouse name)/(branch name), so origin/master points to an remote branch (from that branch our clone data to local), But you cannot change its data locally.
At the same time, Git builds a local master branch of your own, which points to a copy you've just uploaded from remote to your local server. As you continue to change the file, git add, git commit,master point will automatically move, you can also move the master point through the merge (Fast forward).
$git branch-a (to show all the branches git knows about)
* Master
Remotes/origin/head-Origin/master
Remotes/origin/master
$git branch-r (to show remote branches git knows about)
Origin/head-Origin/master
Origin/master
As you can see, Master is the local branch,origin/master that is the remote branch (master was a branch in the local repository. Remotes/origin/master is a branch named Master on the remote named origin)
$git diff origin/master Master (show me the changes between the remote master branch and my Master branch).
It is important to note that the Remotes/origin/master and origin/master points are the same
$git diff origin/master Remotes/origin/master
Git push Origin Master
ORIGIN specifies which remote you want to push to
Master is actually a "refspec", the normal "Refspec" in the form of "+<src>:<dst>", the colon before the name of the local branch, the colon after the remote repository Branch's name. Note that if you omit <dst>,git you think you want to push the branch under remote repository with the same name as local branch. Sounds a bit awkward, and then explain how push is a push method, that is, the local branch point to the commit push to remote repository under the branch, such as
$git Push Origin Master:master (find the branch named Master in local repository, use it to update the branch named Master under Remote repository, If there is no branch under Remote repository name is master, then create a new one)
$Git push origin master (omitted <dst>, equivalent to "Git push Origin master:master")
$git Push Origin Master:refs/for/mybranch (find the branch named Master in local repository, use him to update the remote Repository The following name is Mybranch branch)
$git Push Origin Head:refs/for/mybranch (head pointing to the branch,master of the current job does not necessarily point to the branch of the current job, so I think the head is better than master)
$git Push Origin:mybranch (again origin repository inside find mybranch, delete it. Update it with an empty one, which is equivalent to deleting it.)
This article was forwarded from: http://lishicongli.blog.163.com/blog/static/1468259020132125247302/
Git's origin and master analysis