What is the difference between git clone and checkout?

git clonegit checkout什么区别?


The man page for checkout: http://git-scm.com/docs/git-checkout

The man page for clone: http://git-scm.com/docs/git-clone

To sum it up, clone is for fetching repositories you don't have, checkout is for switching between branches in a repository you already have.

Note: for those who have a SVN/CVS background and new to Git, the equivalent of git clone in SVN/CVS is checkout . The same wording of different terms is often confusing.


git clone is to fetch your repositories from the remote git server.

git checkout is to checkout your desired status of your repository (like branches or particular files).

Eg, you are currently on master branch and you want to switch into develop branch.

git checkout develop_branch

Eg, you want to checkout to a particular status of a particular file

git checkout commit_point_A -- <filename>

Here is a good reference for you to learn Git, lets you understand much more easily.


One thing to notice is the lack of any "Copyout" within git. That's because you already have a full copy in your local repo - your local repo being a clone of your chosen upstream repo. So you have effectively a personal checkout of everything, without putting some 'lock' on those files in the reference repo.

Git provides the SHA1 hash values as the mechanism for verifying that the copy you have of a file / directory tree / commit / repo is exactly the same as that used by whoever is able to declare things as "Master" within the hierarchy of trust. This avoids all those 'locks' that cause most SCM systems to choke (with the usual problems of private copies, big merges, and no real control or management of source code ;-) !

链接地址: http://www.djcxy.com/p/7544.html

上一篇: 在Git中推拉分支

下一篇: git clone和checkout有什么区别?