Reprint: http://lishicongli.blog.163.com/blog/static/1468259020132125247302/
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 remote repository, and the other is the local repository, Again on your own work area. Which
1, 3 Two steps involving the 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 your designated remote Server/repository/branch, and your changes to all files are in your own local Local repository to do, your changes (local branch) and remote branch are independent (parallel). gitk shows the local repository.
Inclone after completion, git origin (origin or view .git/configorigin< Span lang= "ZH-CN"), and download all of the data, create a pointer to its master branch, we use ( remote warehouse name )/( branch name This form represents a remote branch, so origin/masterremote branch< Span lang= "ZH-CN" > (from that branch we 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 files,git add, git commit,Master 's point will automatically move, you can also move through the merge(Fast forward) the point of Master.
$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, and Origin/master is the remote branch(master is 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 indicates the name of the branch under the remote repository. Note that if you omit <dst>, git thinks you want to push to 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 remote repository The next name is Master 's branch, if the remote repository does not exist under the name is master Branch, 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 points to the current working branch, master does not necessarily point to the branch of the current job, so I think the head It's 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.)
[Git] Git's origin and master analysis