Home·Terminal commands

git clone

git

Usage

git clone [--depth <n>] [-b <branch>] <url> [<directory>]

Copies a remote repository with its history; a --depth 1 clone has no old commits and no other branches, so --unshallow is needed later.

Common flags

FlagMeaning
--depth <n>shallow copy with only the last n commits
-b <branch>check out that branch instead of the default
--single-branchfetch one branch only
--recurse-submodulesclone submodules at the same time
--filter=blob:nonepartial clone: fetch file contents on demand
-o <name>call the remote something other than origin

Examples

git clone https://github.com/user/repo.git

copies the repository into repo/ and names the remote origin

git clone --depth 1 https://github.com/user/repo.git

fast copy for CI with no old history

git clone -b dev --single-branch <url>

checks out dev and fetches nothing else

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git clone do?

Copies a remote repository with its history; a --depth 1 clone has no old commits and no other branches, so --unshallow is needed later.

Q. How do I type it?

git clone [--depth <n>] [-b <branch>] <url> [<directory>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-clone