gitclone[--template=<template-directory>] [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror] [-o<name>] [-b<name>] [-u<upload-pack>] [--reference<repository>] [--dissociate] [--separate-git-dir<git-dir>] [--depth<depth>] [--[no-]single-branch] [--no-tags] [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules] [--[no-]remote-submodules] [--jobs<n>] [--sparse] [--[no-]reject-shallow] [--filter=<filter-spec>] [--also-filter-submodules]] [--]<repository> [<directory>]
Clones a repository into a newly created directory, createsremote-tracking branches for each branch in the cloned repository(visible usinggitbranch--remotes), and creates and checks out aninitial branch that is forked from the cloned repository’scurrently active branch.
After the clone, a plaingitfetch without arguments will updateall the remote-tracking branches, and agitpull withoutarguments will in addition merge the remote master branch into thecurrent master branch, if any (this is untrue when--single-branchis given; see below).
This default configuration is achieved by creating references tothe remote branch heads underrefs/remotes/origin andby initializingremote.origin.url andremote.origin.fetchconfiguration variables.
-l--localWhen 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.
If the repository’s$GIT_DIR/objects has symbolic links or is asymbolic link, the clone will fail. This is a security measure toprevent the unintentional copying of files by dereferencing the symboliclinks.
NOTE: this operation can race with concurrent modification to thesource repository, similar to runningcp-rsrcdst while modifyingsrc.
--no-hardlinksForce 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--sharedWhen 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; donot 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 asgitcommit)which automatically callgitmaintenancerun--auto. (Seegit-maintenance[1].) If these objects are removed and were referencedby the cloned repository, then the cloned repository will become corrupt.
Note that runninggitrepack 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 ofclone--shared.It is safe, however, to rungitgc, 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 rungitrepack-a to copy allobjects from the source repository into a pack in the cloned repository.
--reference[-if-able]<repository>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.
--dissociateBorrow 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--quietOperate quietly. Progress is not reported to the standarderror stream.
-v--verboseRun verbosely. Does not affect the reporting of progress statusto the standard error stream.
--progressProgress 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=<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-checkoutNo checkout of HEAD is performed after the clone is complete.
--[no-]reject-shallowFail if the source repository is a shallow repository.Theclone.rejectShallow configuration variable can be used tospecify the default.
--bareMake abare 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 torefs/remotes/origin/. When this option isused, neither remote-tracking branches nor the relatedconfiguration variables are created.
--sparseEmploy a sparse-checkout, with only files in the topleveldirectory initially being present. Thegit-sparse-checkout[1] command can be used to grow theworking directory as needed.
--filter=<filter-spec>Use the partial clone feature and request that the server sendsa subset of reachable objects according to a given object filter.When using--filter, the supplied<filter-spec> is used forthe partial clone filter. For example,--filter=blob:none willfilter out all blobs (file contents) until needed by Git. Also,--filter=blob:limit=<size> will filter out all blobs of sizeat least<size>. For more details on filter specifications, seethe--filter option ingit-rev-list[1].
--also-filter-submodulesAlso apply the partial clone filter to any submodules in the repository.Requires--filter and--recurse-submodules. This can be turned on bydefault by setting theclone.filterSubmodules config option.
--mirrorSet 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 agitremoteupdate in thetarget repository.
-o<name>--origin<name>Instead of using the remote nameorigin to keep track of the upstreamrepository, use<name>. Overridesclone.defaultRemoteName from theconfig.
-b<name>--branch<name>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>--upload-pack<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=<template-directory>Specify the directory from which templates will be used;(See the "TEMPLATE DIRECTORY" section ofgit-init[1].)
-c<key>=<value>--config<key>=<value>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 andremote.<name>.tagOpt. Use thecorresponding--mirror and--no-tags options instead.
--depth<depth>Create ashallow 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=<date>Create a shallow clone with a history after the specified time.
--shallow-exclude=<revision>Create a shallow clone with a history, excluding commitsreachable from a specified remote branch or tag. This optioncan be specified multiple times.
--[no-]single-branchClone only the history leading to the tip of a single branch,either specified by the--branch option or the primarybranch remote’sHEAD 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 theHEAD at the remote did not point at anybranch when--single-branch clone was made, no remote-trackingbranch is created.
--no-tagsDon’t clone any tags, and setremote.<remote>.tagOpt=--no-tags in the config, ensuringthat futuregitpull andgitfetch operations won’t followany tags. Subsequent explicit tag fetches will still work,(seegit-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[=<pathspec>]After the clone is created, initialize and clone submoduleswithin based on the provided<pathspec>. If no=<pathspec> isprovided, all submodules are initialized and cloned.This option can be given multiple times for pathspecs consistingof multiple entries. The resulting clone hassubmodule.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 runninggitsubmoduleupdate--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-submodulesAll submodules which are cloned will be shallow with a depth of 1.
--[no-]remote-submodulesAll 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 togitsubmoduleupdate.
--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.
--ref-format=<ref-format>Specify the given ref storage format for the repository. The valid values are:
files for loose files with packed-refs. This is the default.
reftable for the reftable format. This format is experimental and itsinternals are subject to change.
-j<n>--jobs<n>The number of submodules fetched at the same time.Defaults to thesubmodule.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 andfooforhost.xz:foo/.git). Cloning into an existing directoryis only allowed if the directory is empty.
--bundle-uri=<uri>Before fetching from the remote, fetch a bundle from the given<uri> and unbundle the data into the local repository. The refsin the bundle will be stored under the hiddenrefs/bundle/*namespace. This option is incompatible with--depth,--shallow-since, and--shallow-exclude.
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, ftpand ftps can be used for fetching, but this is inefficient anddeprecated; do not use them).
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>[:<port>]/<path-to-git-repo>
git://<host>[:<port>]/<path-to-git-repo>
http[s]://<host>[:<port>]/<path-to-git-repo>
ftp[s]://<host>[:<port>]/<path-to-git-repo>
An alternative scp-like syntax may also be used with the ssh protocol:
[<user>@]<host>:/<path-to-git-repo>
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 pathfoo: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>[:<port>]/~<user>/<path-to-git-repo>
git://<host>[:<port>]/~<user>/<path-to-git-repo>
[<user>@]<host>:~<user>/<path-to-git-repo>
For local repositories, also supported by Git natively, the followingsyntaxes may be used:
/path/to/repo.git/
These two syntaxes are mostly equivalent, except the former implies--local option.
gitclone,gitfetch andgitpull, but notgitpush, will alsoaccept a suitable bundle file. Seegit-bundle[1].
When Git doesn’t know how to handle a certain transport protocol, itattempts to use theremote-<transport> remote helper, if oneexists. To explicitly request a remote helper, the following syntaxmay be used:
<transport>::<address>
where<address> may be a path, a server and path, or an arbitraryURL-like string recognized by the specific remote helper beinginvoked. Seegitremote-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:
[url "<actual-url-base>"]insteadOf =<other-url-base>
For example, with this:
[url "git://git.host.xz/"]insteadOf = host.xz:/path/to/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:
[url "<actual-url-base>"]pushInsteadOf =<other-url-base>
For example, with this:
[url "ssh://example.org/"]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.
Clone from upstream:
$ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux$ cd my-linux$ make
Make a local clone that borrows from the current directory, without checking things out:
$ git clone -l -s -n . ../copy$ cd ../copy$ git show-branch
Clone from upstream while borrowing from an existing local directory:
$ git clone --reference /git/linux.git \git://git.kernel.org/pub/scm/.../linux.git \my-linux$ cd my-linux
Create a bare repository to publish your changes to the public:
$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
Everything below this line in this section is selectively includedfrom thegit-config[1] documentation. The content is the sameas what’s found there:
init.templateDirSpecify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY" section ofgit-init[1].)
init.defaultBranchAllows overriding the default branch name e.g. when initializinga new repository.
clone.defaultRemoteNameThe name of the remote to create when cloning a repository. Defaults toorigin.It can be overridden by passing the--origin command-lineoption.
clone.rejectShallowReject cloning a repository if it is a shallow one; this can be overridden bypassing the--reject-shallow option on the command line.
clone.filterSubmodulesIf a partial clone filter is provided (see--filter ingit-rev-list[1]) and--recurse-submodules is used, also applythe filter to submodules.
Part of thegit[1] suite