clone
See git clone docs.
Default
$ git clone URL
e.g.
$ git clone git@github.com:MichaelCurrin/dev-cheatsheets.git
Custom directory
$ git clone URL DIRECTORY_NAME
e.g.
$ git clone git@github.com:MichaelCurrin/dev-cheatsheets.git custom-name
$ cd custom-name
Shallow
Clone just one commit, to make downloading quicker. This implies fetching of the one branch only.
$ git clone URL --depth 1
When you check the log, you’ll see something like this.
$ git log
* b385b6c (grafted, HEAD -> master, origin/master, origin/HEAD) Added foo to bar
Branch
Target a branch to clone rather than the default. Just saves having to do cd after.
$ git clone URL --branch my-branch
You probably don’t need to do this, since shallow achies the same.
$ git clone URL --single-branch
Clone a target branch and no others.
$ git clone URL --branch my-branch --single-branch
Flags
--branch <name>Instead of pointing the newly created
HEADto the branch pointed to by the cloned repository’sHEAD, point to<name>branch instead. In a non-bare repository, this is the branch that will be checked out.--branchcan also take tags and detaches theHEADat that commit in the resulting repository.--depth <depth>Create a shallow clone with a history truncated to the specified number of commits.
Implies
--single-branchunless--no-single-branchis given to fetch the histories near the tips of all branches.If you want to clone submodules shallowly, also pass
--shallow-submodules.--single-branchClone only the history leading to the tip of a single branch, either specified by the
--branchoption or the primary branch remote’sHEADpoints at.Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning.
If the
HEADat the remote did not point at any branch when--single-branchclone was made, no remote-tracking branch is created.--shallow-submodulesany cloned submodules will be shallow
--recurse-submodulesinitialize submodules in the clone
--recursivealias of
--recurse-submodules