NAME

git-clone - Clone a repository into a new directory

SYNOPSIS

  1. git clone [--template=<template_directory>]
  2. [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
  3. [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
  4. [--dissociate] [--separate-git-dir <git dir>]
  5. [--depth <depth>] [--[no-]single-branch] [--no-tags]
  6. [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
  7. [--[no-]remote-submodules] [--jobs <n>] [--] <repository>
  8. [<directory>]

DESCRIPTION

Clones a repository into a newly created directory, createsremote-tracking branches for each branch in the cloned repository(visible using git branch —remotes), and creates and checks out aninitial branch that is forked from the cloned repository’scurrently active branch.

After the clone, a plain git fetch without arguments will updateall the remote-tracking branches, and a git pull withoutarguments will in addition merge the remote master branch into thecurrent master branch, if any (this is untrue when "—single-branch"is given; see below).

This default configuration is achieved by creating references tothe remote branch heads under refs/remotes/origin andby initializing remote.origin.url and remote.origin.fetchconfiguration variables.

OPTIONS

  • -l
  • —local
  • When the repository to clone from is on a local machine,this flag bypasses the normal "Git aware" transportmechanism and clones the repository by making a copy ofHEAD and everything under objects and refs directories.The files under .git/objects/ directory are hardlinkedto save space when possible.

If the repository is specified as a local path (e.g., /path/to/repo),this is the default, and —local is essentially a no-op. If therepository is specified as a URL, then this flag is ignored (and wenever use the local optimizations). Specifying —no-local willoverride the default when /path/to/repo is given, using the regularGit transport instead.

  • —no-hardlinks
  • Force the cloning process from a repository on a localfilesystem to copy the files under the .git/objectsdirectory instead of using hardlinks. This may be desirableif you are trying to make a back-up of your repository.

  • -s

  • —shared
  • When the repository to clone is on the local machine,instead of using hard links, automatically setup.git/objects/info/alternates to share the objectswith the source repository. The resulting repositorystarts out without any object of its own.

NOTE: this is a possibly dangerous operation; do not useit unless you understand what it does. If you clone yourrepository using this option and then delete branches (or use anyother Git command that makes any existing commit unreferenced) in thesource repository, some objects may become unreferenced (or dangling).These objects may be removed by normal Git operations (such as git commit)which automatically call git gc —auto. (See git-gc[1].)If these objects are removed and were referenced by the cloned repository,then the cloned repository will become corrupt.

Note that running git repack without the —local option in a repositorycloned with —shared will copy objects from the source repository into a packin the cloned repository, removing the disk space savings of clone —shared.It is safe, however, to run git gc, which uses the —local option bydefault.

If you want to break the dependency of a repository cloned with —shared onits source repository, you can simply run git repack -a to copy allobjects from the source repository into a pack in the cloned repository.

  • —reference[-if-able]
  • If the reference repository is on the local machine,automatically setup .git/objects/info/alternates toobtain objects from the reference repository. Usingan already existing repository as an alternate willrequire fewer objects to be copied from the repositorybeing cloned, reducing network and local storage costs.When using the —reference-if-able, a non existingdirectory is skipped with a warning instead of abortingthe clone.

NOTE: see the NOTE for the —shared option, and also the—dissociate option.

  • —dissociate
  • Borrow the objects from reference repositories specifiedwith the —reference options only to reduce networktransfer, and stop borrowing from them after a clone is madeby making necessary local copies of borrowed objects. Thisoption can also be used when cloning locally from arepository that already borrows objects from anotherrepository—​the new repository will borrow objects from thesame repository, and this option can be used to stop theborrowing.

  • -q

  • —quiet
  • Operate quietly. Progress is not reported to the standarderror stream.

  • -v

  • —verbose
  • Run verbosely. Does not affect the reporting of progress statusto the standard error stream.

  • —progress

  • Progress status is reported on the standard error streamby default when it is attached to a terminal, unless —quietis specified. This flag forces progress status even if thestandard error stream is not directed to a terminal.

  • —server-option=

  • Transmit the given string to the server when communicating usingprotocol version 2. The given string must not contain a NUL or LFcharacter. The server’s handling of server options, includingunknown ones, is server-specific.When multiple —server-option=<option> are given, they are allsent to the other side in the order listed on the command line.

  • -n

  • —no-checkout
  • No checkout of HEAD is performed after the clone is complete.

  • —bare

  • Make a bare Git repository. That is, instead ofcreating <directory> and placing the administrativefiles in <directory>/.git, make the <directory>itself the $GIT_DIR. This obviously implies the —no-checkoutbecause there is nowhere to check out the working tree.Also the branch heads at the remote are copied directlyto corresponding local branch heads, without mappingthem to refs/remotes/origin/. When this option isused, neither remote-tracking branches nor the relatedconfiguration variables are created.

  • —mirror

  • Set up a mirror of the source repository. This implies —bare.Compared to —bare, —mirror not only maps local branches of thesource to local branches of the target, it maps all refs (includingremote-tracking branches, notes etc.) and sets up a refspec configuration suchthat all these refs are overwritten by a git remote update in thetarget repository.

  • -o

  • —origin
  • Instead of using the remote name origin to keep trackof the upstream repository, use <name>.

  • -b

  • —branch
  • Instead of pointing the newly created HEAD to the branch pointedto by the cloned repository’s HEAD, point to <name> branchinstead. In a non-bare repository, this is the branch that willbe checked out.—branch can also take tags and detaches the HEAD at that commitin the resulting repository.

  • -u

  • —upload-pack
  • When given, and the repository to clone from is accessedvia ssh, this specifies a non-default path for the commandrun on the other end.

  • —template=

  • Specify the directory from which templates will be used;(See the "TEMPLATE DIRECTORY" section of git-init[1].)

  • -c =

  • —config =
  • Set a configuration variable in the newly-created repository;this takes effect immediately after the repository isinitialized, but before the remote history is fetched or anyfiles checked out. The key is in the same format as expected bygit-config[1] (e.g., core.eol=true). If multiplevalues are given for the same key, each value will be written tothe config file. This makes it safe, for example, to addadditional fetch refspecs to the origin remote.

Due to limitations of the current implementation, some configurationvariables do not take effect until after the initial fetch and checkout.Configuration variables known to not take effect are:remote.<name>.mirror and remote.<name>.tagOpt. Use thecorresponding —mirror and —no-tags options instead.

  • —depth
  • Create a shallow clone with a history truncated to thespecified number of commits. Implies —single-branch unless—no-single-branch is given to fetch the histories near thetips of all branches. If you want to clone submodules shallowly,also pass —shallow-submodules.

  • —shallow-since=

  • Create a shallow clone with a history after the specified time.

  • —shallow-exclude=

  • Create a shallow clone with a history, excluding commitsreachable from a specified remote branch or tag. This optioncan be specified multiple times.

  • —[no-]single-branch

  • Clone only the history leading to the tip of a single branch,either specified by the —branch option or the primarybranch remote’s HEAD points at.Further fetches into the resulting repository will only update theremote-tracking branch for the branch this option was used for theinitial cloning. If the HEAD at the remote did not point at anybranch when —single-branch clone was made, no remote-trackingbranch is created.

  • —no-tags

  • Don’t clone any tags, and setremote.<remote>.tagOpt=—no-tags in the config, ensuringthat future git pull and git fetch operations won’t followany tags. Subsequent explicit tag fetches will still work,(see git-fetch[1]).

Can be used in conjunction with —single-branch to clone andmaintain a branch with no references other than a single clonedbranch. This is useful e.g. to maintain minimal clones of the defaultbranch of some repository for search indexing.

  • —recurse-submodules[=submodule.active="" set="" tothe="" provided="" pathspec,="" or="" "."="" (meaning="" all="" submodules)="" if="" nopathspec="" is="" provided.="" submodules="" are="" initialized="" and="" cloned="" using="" their="" default="" settings.="" this="" isequivalent="" to="" runninggit submodule update —init —recursive <pathspec>="" immediately="" afterthe="" clone="" is="" finished.="" this="" option="" is="" ignored="" if="" the="" cloned="" repository="" doesnot="" have="" a="" worktree="" checkout="" (i.e.="" if="" any="" of="" —no-checkout="" -n,="" —bare,or="" —mirror="" is="" given)="" -="" —[no-]shallow-submodules="" -="" all="" submodules="" which="" are="" cloned="" will="" be="" shallow="" with="" a="" depth="" of="" 1.="" -="" —[no-]remote-submodules="" -="" all="" submodules="" which="" are="" cloned="" will="" use="" the="" status="" of="" the="" submodule’sremote-tracking="" branch="" to="" update="" the="" submodule,="" rather="" than="" thesuperproject’s="" recorded="" sha-1.="" equivalent="" to="" passing="" —remote="" togit submodule update.="" -="" —separate-git-dir="<git" dir="">
  • Instead of placing the cloned repository where it is supposedto be, place the cloned repository at the specified directory,then make a filesystem-agnostic Git symbolic link to there.The result is Git repository can be separated from workingtree.

  • -j

  • —jobs
  • The number of submodules fetched at the same time.Defaults to the submodule.fetchJobs option.

  • The (possibly remote) repository to clone from. See theGIT URLS section below for more information on specifyingrepositories.

  • The name of a new directory to clone into. The "humanish"part of the source repository is used if no directory isexplicitly given (repo for /path/to/repo.git and foofor host.xz:foo/.git). Cloning into an existing directoryis only allowed if the directory is empty.

GIT URLS

In general, URLs contain information about the transport protocol, theaddress of the remote server, and the path to the repository.Depending on the transport protocol, some of this information may beabsent.

Git supports ssh, git, http, and https protocols (in addition, ftp,and ftps can be used for fetching, but this is inefficient anddeprecated; do not use it).

The native transport (i.e. git:// URL) does no authentication andshould be used with caution on unsecured networks.

The following syntaxes may be used with them:

  • ssh://[user@]host.xz[:port]/path/to/repo.git/

  • git://host.xz[:port]/path/to/repo.git/

  • http[s]://host.xz[:port]/path/to/repo.git/

  • ftp[s]://host.xz[:port]/path/to/repo.git/

An alternative scp-like syntax may also be used with the ssh protocol:

  • [user@]host.xz:path/to/repo.git/

This syntax is only recognized if there are no slashes before thefirst colon. This helps differentiate a local path that contains acolon. For example the local path foo:bar could be specified as anabsolute path or ./foo:bar to avoid being misinterpreted as an sshurl.

The ssh and git protocols additionally support ~username expansion:

  • ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/

  • git://host.xz[:port]/~[user]/path/to/repo.git/

  • [user@]host.xz:/~[user]/path/to/repo.git/

For local repositories, also supported by Git natively, the followingsyntaxes may be used:

  • /path/to/repo.git/

  • file:///path/to/repo.git/

These two syntaxes are mostly equivalent, except the former implies—local option.

When Git doesn’t know how to handle a certain transport protocol, itattempts to use the remote-<transport> remote helper, if oneexists. To explicitly request a remote helper, the following syntaxmay be used:

  • ::

where <address> may be a path, a server and path, or an arbitraryURL-like string recognized by the specific remote helper beinginvoked. See gitremote-helpers[7] for details.

If there are a large number of similarly-named remote repositories andyou want to use a different format for them (such that the URLs youuse will be rewritten into URLs that work), you can create aconfiguration section of the form:

  1. [url "<actual url base>"]
  2. insteadOf = <other url base>

For example, with this:

  1. [url "git://git.host.xz/"]
  2. insteadOf = host.xz:/path/to/
  3. insteadOf = work:

a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will berewritten in any context that takes a URL to be "git://git.host.xz/repo.git".

If you want to rewrite URLs for push only, you can create aconfiguration section of the form:

  1. [url "<actual url base>"]
  2. pushInsteadOf = <other url base>

For example, with this:

  1. [url "ssh://example.org/"]
  2. pushInsteadOf = git://example.org/

a URL like "git://example.org/path/to/repo.git" will be rewritten to"ssh://example.org/path/to/repo.git" for pushes, but pulls will stilluse the original URL.

EXAMPLES

  • Clone from upstream:
  1. $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
  2. $ cd my-linux
  3. $ make
  • Make a local clone that borrows from the current directory, without checking things out:
  1. $ git clone -l -s -n . ../copy
  2. $ cd ../copy
  3. $ git show-branch
  • Clone from upstream while borrowing from an existing local directory:
  1. $ git clone --reference /git/linux.git \
  2. git://git.kernel.org/pub/scm/.../linux.git \
  3. my-linux
  4. $ cd my-linux
  • Create a bare repository to publish your changes to the public:
  1. $ git clone --bare -l /home/proj/.git /pub/scm/proj.git

GIT

Part of the git[1] suite