Git - git-clone Documentation (2024)

-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.

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 running cp -r src dst while modifyingsrc.

--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

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 maintenance run --auto. (Seegit-maintenance[1].) If these objects are removed and were referencedby 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] <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.

--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=<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.

--[no-]reject-shallow

Fail if the source repository is a shallow repository.The clone.rejectShallow configuration variable can be used tospecify the default.

--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.

--sparse

Employ 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 in git-rev-list[1].

--also-filter-submodules

Also apply the partial clone filter to any submodules in the repository.Requires --filter and --recurse-submodules. This can be turned on bydefault by setting the clone.filterSubmodules config option.

--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 <name>
--origin <name>

Instead of using the remote name origin to keep track of the upstreamrepository, use <name>. Overrides clone.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 of git-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 and remote.<name>.tagOpt. Use thecorresponding --mirror and --no-tags options instead.

--depth <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=<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-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[=<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 has 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.

--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 the submodule.fetchJobs option.

<repository>

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

<directory>

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.

--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 hidden refs/bundle/*namespace. This option is incompatible with --depth,--shallow-since, and --shallow-exclude.

Git - git-clone Documentation (2024)
Top Articles
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 5873

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.