What is the difference between git clone and checkout?

GitCommand

Git Problem Overview


What is the difference between git clone and git checkout?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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).

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

git checkout develop_branch

E.g., 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.

Solution 3 - Git

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 ;-) !

Solution 4 - Git

Simply git checkout have 2 uses

  1. Switching between existing local branches like git checkout <existing_local_branch_name>
  2. Create a new branch from current branch using flag -b. Suppose if you are at master branch then git checkout -b <new_feature_branch_name> will create a new branch with the contents of master and switch to newly created branch

You can find more options at the official site

Solution 5 - Git

checkout can be use for many case :

1st case : switch between branch in local repository For instance :

 git checkout exists_branch_to_switch

You can also create new branch and switch out in throught this case with -b

 git checkout -b new_branch_to_switch

2nd case : restore file from x rev

 git checkout rev file_to_restore

...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPraveen SripatiView Question on Stackoverflow
Solution 1 - GitAugust LilleaasView Answer on Stackoverflow
Solution 2 - GitTheOneTeamView Answer on Stackoverflow
Solution 3 - GitPhilip OakleyView Answer on Stackoverflow
Solution 4 - GitKhader M AView Answer on Stackoverflow
Solution 5 - GitGomsView Answer on Stackoverflow