Git Clone
Shallow Clone¶
Cloning a huge repository (like a project with multiple years of history) might take a long time, or fail because of the amount of data to be transferred. In cases where you don't need to have the full history available, you can do a shallow clone:
The above command will fetch just the last commit from the remote repository.
Be aware that you may not be able to resolve merges in a shallow repository. It's often a good idea to take at least as many commits are you are going to need to backtrack to resolve merges.
For example, to instead get the last 50 commits:
Regular Clone¶
To download the entire repository including the full history and all branches, type:
The example above will place it in a directory with the same name as the repository name.
To download the repository and save it in a specific directory, type:
Clone a specific branch¶
To clone a specific branch of a repository, type --branch <branch name> before the repository url:
To use the shorthand option for --branch, type -b. This command downloads entire repository and checks out <branch name>.
To save disk space you can clone history leading only to single branch with:
Tip
If you cloned with --single-branch and later need all branches, run:
Clone recursively¶
Clones the repository and also clones all submodules. If the submodules themselves contain additional submodules, Git will also clone those.
Clone using a proxy¶
If you need to download files with git under a proxy, setting proxy server system-wide couldn't be enough. You could also try the following:
References¶
For more information on cloning repositories, visit the official Git documentation.