GIT: Problems Understanding Branch Naming Convention
I am having problem understanding the differences between 'master' 'origin master' 'origin/master', 'remotes/origin/master'!! Is there any rule for naming GIT branches? I suppose 'origin master' is the master branch in the repository while origin/master is my local reflection of the repository master branch, then what is remotes/origin/master?! Also, sometimes I have开发者_JAVA技巧 to use origin/master to refer to the repository master branch (I forget the case though, but I feel I have been into such thing before), why is that?
You should read up on the git branching model to understand this properly. However, following is a quick and dirty explanation.
Branches in git are pointers to certain nodes in the DAG tree of commits. They will move when you perform some operations (e.g. a commit). master
is one such pointer which is by default the one created when you initialise a fresh repository. It's your "main branch" (so to speak).
Since git is a distributed version control system, there's a difference between your local repository and a remote one (like one on github). These are called remote
s and when you clone for the first time, the remote from which you cloned is automatically created and named origin
(i.e. where your code originated from).
When you say <remote>/<branch>
, it's referring the location of the pointer <branch>
not on your local clone but on the <remote>
. So if, after cloning, you make 10 commits to your local branch, master
(your local branch) will be 10 commits ahead of origin/master
. To make it clear to git that we're talking about a remote, the convention remotes/<remote_name>/<branch_name>
is used.
I think you need to read the book which I've linked to before you use git. It's a little non-intuitive for people coming from a version control system like svn
or others. The branching model for git is a lot simpler than the ones for centralised systems.
精彩评论