In fact, in Git, the act of creating a new branch is simply writing a file in the .git/refs/heads directory that has the SHA-1 of the last commit for that branch.
Creating a branch is nothing more than just writing 40 characters to a file.
Switching to that branch simply means having Git make your working directory look like the tree that SHA-1 points to and updating the HEAD file so each commit from that point on moves that branch pointer forward (in other words, it changes the 40 characters in .git/refs/heads/[current_branch_name] be the SHA-1 of your last commit).
可以看到,在git
中,创建一个branch
仅仅是在一个文件中加入40
个字符的SHA-1
值。
Remotes are basically pointers to branches in other peoples copies of the same repository, often on other computers. If you got your repository by cloning it, rather than initializing it, you should have a remote branch of where you copied it from automatically added as origin by default. Which means the tree that was checked out during your initial clone would be referenced as origin/master , which means “the master branch of the origin remote.”
Remotes
是指向其它人关于这个repository copy
里某个branch
的指针。如果你的repository
是通过clone
其它copy
得到的,而不是initialize
的,在你的repository
里,会自动产生一个origin/master
的remote branch
指向你copy
的repository tree
。
参考资料:
Git internals。