Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 1 | git-clone(1) |
| 2 | ============ |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 3 | |
| 4 | NAME |
| 5 | ---- |
william pursell | 29cf5e1 | 2007-06-09 16:44:12 +0100 | [diff] [blame] | 6 | git-clone - Clone a repository into a new directory |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Jonas Fonseca | 353ce81 | 2005-12-31 18:37:15 +0100 | [diff] [blame] | 11 | [verse] |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 12 | `git clone` [++--template=++__<template-directory>__] |
| 13 | [`-l`] [`-s`] [`--no-hardlinks`] [`-q`] [`-n`] [`--bare`] [`--mirror`] |
| 14 | [`-o` _<name>_] [`-b` _<name>_] [`-u` _<upload-pack>_] [`--reference` _<repository>_] |
| 15 | [`--dissociate`] [`--separate-git-dir` _<git-dir>_] |
| 16 | [`--depth` _<depth>_] [`--`[`no-`]`single-branch`] [`--no-tags`] |
| 17 | [++--recurse-submodules++[++=++__<pathspec>__]] [`--`[`no-`]`shallow-submodules`] |
| 18 | [`--`[`no-`]`remote-submodules`] [`--jobs` _<n>_] [`--sparse`] [`--`[`no-`]`reject-shallow`] |
| 19 | [++--filter=++__<filter-spec>__] [`--also-filter-submodules`]] [`--`] _<repository>_ |
| 20 | [_<directory>_] |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 21 | |
| 22 | DESCRIPTION |
| 23 | ----------- |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 24 | |
J. Bruce Fields | db9819a | 2006-12-08 01:27:21 -0500 | [diff] [blame] | 25 | Clones a repository into a newly created directory, creates |
| 26 | remote-tracking branches for each branch in the cloned repository |
Quentin Nerden | 3711d1c | 2019-07-02 07:37:40 -0700 | [diff] [blame] | 27 | (visible using `git branch --remotes`), and creates and checks out an |
Jonathan Nieder | 33405be | 2009-10-09 18:07:39 -0500 | [diff] [blame] | 28 | initial branch that is forked from the cloned repository's |
| 29 | currently active branch. |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 30 | |
J. Bruce Fields | db9819a | 2006-12-08 01:27:21 -0500 | [diff] [blame] | 31 | After the clone, a plain `git fetch` without arguments will update |
| 32 | all the remote-tracking branches, and a `git pull` without |
| 33 | arguments will in addition merge the remote master branch into the |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 34 | current master branch, if any (this is untrue when `--single-branch` |
Ralf Thielow | 31b808a | 2012-09-20 20:04:08 +0200 | [diff] [blame] | 35 | is given; see below). |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 36 | |
J. Bruce Fields | db9819a | 2006-12-08 01:27:21 -0500 | [diff] [blame] | 37 | This default configuration is achieved by creating references to |
Jeff King | cc1b8d8 | 2010-02-17 20:16:20 -0500 | [diff] [blame] | 38 | the remote branch heads under `refs/remotes/origin` and |
J. Bruce Fields | db9819a | 2006-12-08 01:27:21 -0500 | [diff] [blame] | 39 | by initializing `remote.origin.url` and `remote.origin.fetch` |
| 40 | configuration variables. |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 41 | |
Junio C Hamano | f4bf218 | 2007-01-01 15:08:06 -0800 | [diff] [blame] | 42 | |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 43 | OPTIONS |
| 44 | ------- |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 45 | `-l`:: |
| 46 | `--local`:: |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 47 | When the repository to clone from is on a local machine, |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 48 | this flag bypasses the normal "Git aware" transport |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 49 | mechanism and clones the repository by making a copy of |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 50 | `HEAD` and everything under objects and refs directories. |
Junio C Hamano | 3d5c418 | 2007-08-01 23:42:36 -0700 | [diff] [blame] | 51 | The files under `.git/objects/` directory are hardlinked |
Jeff King | 9197a10 | 2012-05-30 07:09:08 -0400 | [diff] [blame] | 52 | to save space when possible. |
| 53 | + |
| 54 | If the repository is specified as a local path (e.g., `/path/to/repo`), |
| 55 | this is the default, and --local is essentially a no-op. If the |
| 56 | repository is specified as a URL, then this flag is ignored (and we |
Jeff King | 189260b | 2012-05-30 07:10:16 -0400 | [diff] [blame] | 57 | never use the local optimizations). Specifying `--no-local` will |
| 58 | override the default when `/path/to/repo` is given, using the regular |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 59 | Git transport instead. |
Taylor Blau | a4a1ca2 | 2021-01-11 14:25:10 -0500 | [diff] [blame] | 60 | + |
Glen Choo | 4e33535 | 2023-04-10 22:18:50 +0000 | [diff] [blame] | 61 | If the repository's `$GIT_DIR/objects` has symbolic links or is a |
| 62 | symbolic link, the clone will fail. This is a security measure to |
| 63 | prevent the unintentional copying of files by dereferencing the symbolic |
| 64 | links. |
| 65 | + |
Taylor Blau | a4a1ca2 | 2021-01-11 14:25:10 -0500 | [diff] [blame] | 66 | *NOTE*: this operation can race with concurrent modification to the |
| 67 | source repository, similar to running `cp -r src dst` while modifying |
| 68 | `src`. |
Junio C Hamano | 3d5c418 | 2007-08-01 23:42:36 -0700 | [diff] [blame] | 69 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 70 | `--no-hardlinks`:: |
Albert L. Lash, IV | 897e3e4 | 2014-02-08 15:41:36 -0500 | [diff] [blame] | 71 | Force the cloning process from a repository on a local |
| 72 | filesystem to copy the files under the `.git/objects` |
| 73 | directory instead of using hardlinks. This may be desirable |
| 74 | if you are trying to make a back-up of your repository. |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 75 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 76 | `-s`:: |
| 77 | `--shared`:: |
Eric W. Biederman | a2775c2 | 2005-10-02 13:42:57 -0600 | [diff] [blame] | 78 | When the repository to clone is on the local machine, |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 79 | instead of using hard links, automatically setup |
Björn Gustavsson | 550c66f | 2009-10-20 22:38:38 +0200 | [diff] [blame] | 80 | `.git/objects/info/alternates` to share the objects |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 81 | with the source repository. The resulting repository |
| 82 | starts out without any object of its own. |
Miklos Vajna | 8466887 | 2008-02-12 01:12:57 +0100 | [diff] [blame] | 83 | + |
| 84 | *NOTE*: this is a possibly dangerous operation; do *not* use |
| 85 | it unless you understand what it does. If you clone your |
Brandon Casey | 2498a1a | 2008-04-03 13:26:13 -0500 | [diff] [blame] | 86 | repository using this option and then delete branches (or use any |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 87 | other Git command that makes any existing commit unreferenced) in the |
Brandon Casey | 2498a1a | 2008-04-03 13:26:13 -0500 | [diff] [blame] | 88 | source repository, some objects may become unreferenced (or dangling). |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 89 | These objects may be removed by normal Git operations (such as `git commit`) |
Derrick Stolee | a95ce12 | 2020-09-17 18:11:44 +0000 | [diff] [blame] | 90 | which automatically call `git maintenance run --auto`. (See |
| 91 | linkgit:git-maintenance[1].) If these objects are removed and were referenced |
| 92 | by the cloned repository, then the cloned repository will become corrupt. |
Jeff King | 13354f5 | 2009-08-17 02:19:17 -0400 | [diff] [blame] | 93 | + |
Quentin Nerden | 3711d1c | 2019-07-02 07:37:40 -0700 | [diff] [blame] | 94 | Note that running `git repack` without the `--local` option in a repository |
| 95 | cloned with `--shared` will copy objects from the source repository into a pack |
| 96 | in the cloned repository, removing the disk space savings of `clone --shared`. |
| 97 | It is safe, however, to run `git gc`, which uses the `--local` option by |
Jeff King | 13354f5 | 2009-08-17 02:19:17 -0400 | [diff] [blame] | 98 | default. |
| 99 | + |
Quentin Nerden | 3711d1c | 2019-07-02 07:37:40 -0700 | [diff] [blame] | 100 | If you want to break the dependency of a repository cloned with `--shared` on |
Jeff King | 13354f5 | 2009-08-17 02:19:17 -0400 | [diff] [blame] | 101 | its source repository, you can simply run `git repack -a` to copy all |
| 102 | objects from the source repository into a pack in the cloned repository. |
Eric W. Biederman | a2775c2 | 2005-10-02 13:42:57 -0600 | [diff] [blame] | 103 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 104 | `--reference`[`-if-able`] _<repository>_:: |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 105 | If the reference _<repository>_ is on the local machine, |
Björn Gustavsson | 550c66f | 2009-10-20 22:38:38 +0200 | [diff] [blame] | 106 | automatically setup `.git/objects/info/alternates` to |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 107 | obtain objects from the reference _<repository>_. Using |
Shawn Pearce | 23edecb | 2006-04-18 20:19:48 -0400 | [diff] [blame] | 108 | an already existing repository as an alternate will |
Mike Ralphson | 451e593 | 2007-09-07 17:43:37 +0100 | [diff] [blame] | 109 | require fewer objects to be copied from the repository |
Shawn Pearce | 23edecb | 2006-04-18 20:19:48 -0400 | [diff] [blame] | 110 | being cloned, reducing network and local storage costs. |
Stefan Beller | f7415b4 | 2016-08-15 14:53:26 -0700 | [diff] [blame] | 111 | When using the `--reference-if-able`, a non existing |
| 112 | directory is skipped with a warning instead of aborting |
| 113 | the clone. |
Brandon Casey | 2498a1a | 2008-04-03 13:26:13 -0500 | [diff] [blame] | 114 | + |
Junio C Hamano | fb1d6da | 2014-10-14 12:38:52 -0700 | [diff] [blame] | 115 | *NOTE*: see the NOTE for the `--shared` option, and also the |
| 116 | `--dissociate` option. |
| 117 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 118 | `--dissociate`:: |
Junio C Hamano | fb1d6da | 2014-10-14 12:38:52 -0700 | [diff] [blame] | 119 | Borrow the objects from reference repositories specified |
| 120 | with the `--reference` options only to reduce network |
Alex Riesen | 0181681 | 2015-10-22 18:41:17 +0200 | [diff] [blame] | 121 | transfer, and stop borrowing from them after a clone is made |
| 122 | by making necessary local copies of borrowed objects. This |
| 123 | option can also be used when cloning locally from a |
| 124 | repository that already borrows objects from another |
| 125 | repository--the new repository will borrow objects from the |
| 126 | same repository, and this option can be used to stop the |
| 127 | borrowing. |
Shawn Pearce | 23edecb | 2006-04-18 20:19:48 -0400 | [diff] [blame] | 128 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 129 | `-q`:: |
| 130 | `--quiet`:: |
Tay Ray Chuan | 488c316 | 2009-12-26 01:12:04 +0800 | [diff] [blame] | 131 | Operate quietly. Progress is not reported to the standard |
Jeff King | 0d0bac6 | 2016-01-30 02:21:26 -0500 | [diff] [blame] | 132 | error stream. |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 133 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 134 | `-v`:: |
| 135 | `--verbose`:: |
Tay Ray Chuan | c54b74a | 2010-02-24 20:50:20 +0800 | [diff] [blame] | 136 | Run verbosely. Does not affect the reporting of progress status |
| 137 | to the standard error stream. |
Tay Ray Chuan | 5a518ad | 2009-12-26 01:12:06 +0800 | [diff] [blame] | 138 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 139 | `--progress`:: |
Tay Ray Chuan | 488c316 | 2009-12-26 01:12:04 +0800 | [diff] [blame] | 140 | Progress status is reported on the standard error stream |
Quentin Nerden | 3711d1c | 2019-07-02 07:37:40 -0700 | [diff] [blame] | 141 | by default when it is attached to a terminal, unless `--quiet` |
Tay Ray Chuan | 488c316 | 2009-12-26 01:12:04 +0800 | [diff] [blame] | 142 | is specified. This flag forces progress status even if the |
| 143 | standard error stream is not directed to a terminal. |
Miklos Vajna | 21188b1 | 2008-10-09 01:40:32 +0200 | [diff] [blame] | 144 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 145 | ++--server-option=++__<option>__:: |
Jonathan Tan | 6e98305 | 2019-04-12 12:51:22 -0700 | [diff] [blame] | 146 | Transmit the given string to the server when communicating using |
| 147 | protocol version 2. The given string must not contain a NUL or LF |
| 148 | character. The server's handling of server options, including |
| 149 | unknown ones, is server-specific. |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 150 | When multiple ++--server-option=++__<option>__ are given, they are all |
Jonathan Tan | 6e98305 | 2019-04-12 12:51:22 -0700 | [diff] [blame] | 151 | sent to the other side in the order listed on the command line. |
| 152 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 153 | `-n`:: |
| 154 | `--no-checkout`:: |
Eric W. Biederman | a2775c2 | 2005-10-02 13:42:57 -0600 | [diff] [blame] | 155 | No checkout of HEAD is performed after the clone is complete. |
| 156 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 157 | `--`[`no-`]`reject-shallow`:: |
Li Linchao | 4fe788b | 2021-04-01 10:46:59 +0000 | [diff] [blame] | 158 | Fail if the source repository is a shallow repository. |
Jean-Noël Avila | d3717e1 | 2024-03-10 19:10:29 +0000 | [diff] [blame] | 159 | The `clone.rejectShallow` configuration variable can be used to |
Li Linchao | 4fe788b | 2021-04-01 10:46:59 +0000 | [diff] [blame] | 160 | specify the default. |
| 161 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 162 | `--bare`:: |
Thomas Ackermann | 48a8c26 | 2013-01-21 20:16:20 +0100 | [diff] [blame] | 163 | Make a 'bare' Git repository. That is, instead of |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 164 | creating _<directory>_ and placing the administrative |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 165 | files in _<directory>_`/.git`, make the _<directory>_ |
Quentin Nerden | 3711d1c | 2019-07-02 07:37:40 -0700 | [diff] [blame] | 166 | itself the `$GIT_DIR`. This obviously implies the `--no-checkout` |
Petr Baudis | 7182135 | 2006-11-23 23:58:35 +0100 | [diff] [blame] | 167 | because there is nowhere to check out the working tree. |
| 168 | Also the branch heads at the remote are copied directly |
| 169 | to corresponding local branch heads, without mapping |
| 170 | them to `refs/remotes/origin/`. When this option is |
J. Bruce Fields | 36566cc | 2006-12-31 18:47:34 -0500 | [diff] [blame] | 171 | used, neither remote-tracking branches nor the related |
| 172 | configuration variables are created. |
Junio C Hamano | 8a1a120 | 2006-01-14 16:00:32 -0800 | [diff] [blame] | 173 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 174 | `--sparse`:: |
Elijah Newren | d30e2bb | 2021-12-14 04:09:11 +0000 | [diff] [blame] | 175 | Employ a sparse-checkout, with only files in the toplevel |
| 176 | directory initially being present. The |
| 177 | linkgit:git-sparse-checkout[1] command can be used to grow the |
| 178 | working directory as needed. |
Derrick Stolee | d89f09c | 2019-11-21 22:04:35 +0000 | [diff] [blame] | 179 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 180 | ++--filter=++__<filter-spec>__:: |
Derrick Stolee | 4a46544 | 2020-03-22 19:50:06 +0000 | [diff] [blame] | 181 | Use the partial clone feature and request that the server sends |
| 182 | a subset of reachable objects according to a given object filter. |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 183 | When using `--filter`, the supplied _<filter-spec>_ is used for |
Derrick Stolee | 4a46544 | 2020-03-22 19:50:06 +0000 | [diff] [blame] | 184 | the partial clone filter. For example, `--filter=blob:none` will |
| 185 | filter out all blobs (file contents) until needed by Git. Also, |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 186 | ++--filter=blob:limit=++__<size>__ will filter out all blobs of size |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 187 | at least _<size>_. For more details on filter specifications, see |
Derrick Stolee | 4a46544 | 2020-03-22 19:50:06 +0000 | [diff] [blame] | 188 | the `--filter` option in linkgit:git-rev-list[1]. |
| 189 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 190 | `--also-filter-submodules`:: |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 191 | Also apply the partial clone filter to any submodules in the repository. |
| 192 | Requires `--filter` and `--recurse-submodules`. This can be turned on by |
| 193 | default by setting the `clone.filterSubmodules` config option. |
| 194 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 195 | `--mirror`:: |
Uwe Kleine-König | 6db2103 | 2010-10-04 19:28:27 +0200 | [diff] [blame] | 196 | Set up a mirror of the source repository. This implies `--bare`. |
| 197 | Compared to `--bare`, `--mirror` not only maps local branches of the |
| 198 | source to local branches of the target, it maps all refs (including |
Matthieu Moy | 29b9a66 | 2010-11-02 16:31:24 +0100 | [diff] [blame] | 199 | remote-tracking branches, notes etc.) and sets up a refspec configuration such |
Uwe Kleine-König | 6db2103 | 2010-10-04 19:28:27 +0200 | [diff] [blame] | 200 | that all these refs are overwritten by a `git remote update` in the |
| 201 | target repository. |
Johannes Schindelin | bc699af | 2008-08-02 21:38:56 +0200 | [diff] [blame] | 202 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 203 | `-o` _<name>_:: |
| 204 | `--origin` _<name>_:: |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 205 | Instead of using the remote name `origin` to keep track of the upstream |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 206 | repository, use _<name>_. Overrides `clone.defaultRemoteName` from the |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 207 | config. |
Johannes Schindelin | e6c310f | 2005-12-22 23:37:24 +0100 | [diff] [blame] | 208 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 209 | `-b` _<name>_:: |
| 210 | `--branch` _<name>_:: |
Jeff King | 7a4ee28 | 2009-08-26 15:05:08 -0400 | [diff] [blame] | 211 | Instead of pointing the newly created HEAD to the branch pointed |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 212 | to by the cloned repository's HEAD, point to _<name>_ branch |
Ralf Thielow | 31b808a | 2012-09-20 20:04:08 +0200 | [diff] [blame] | 213 | instead. In a non-bare repository, this is the branch that will |
| 214 | be checked out. |
| 215 | `--branch` can also take tags and detaches the HEAD at that commit |
| 216 | in the resulting repository. |
Jeff King | 7a4ee28 | 2009-08-26 15:05:08 -0400 | [diff] [blame] | 217 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 218 | `-u` _<upload-pack>_:: |
| 219 | `--upload-pack` _<upload-pack>_:: |
Steve Haslam | d3296e3 | 2008-07-25 19:37:48 +0100 | [diff] [blame] | 220 | When given, and the repository to clone from is accessed |
| 221 | via ssh, this specifies a non-default path for the command |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 222 | run on the other end. |
| 223 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 224 | ++--template=++__<template-directory>__:: |
Junio C Hamano | a57c8ba | 2006-05-28 10:14:38 -0700 | [diff] [blame] | 225 | Specify the directory from which templates will be used; |
Steven Drake | d8a8488 | 2010-02-17 12:44:46 +1300 | [diff] [blame] | 226 | (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].) |
Junio C Hamano | a57c8ba | 2006-05-28 10:14:38 -0700 | [diff] [blame] | 227 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 228 | `-c` __<key>__++=++__<value>__:: |
| 229 | `--config` __<key>__++=++__<value>__:: |
Jeff King | 84054f7 | 2011-06-09 16:56:19 -0400 | [diff] [blame] | 230 | Set a configuration variable in the newly-created repository; |
| 231 | this takes effect immediately after the repository is |
| 232 | initialized, but before the remote history is fetched or any |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 233 | files checked out. The _<key>_ is in the same format as expected by |
Jeff King | 84054f7 | 2011-06-09 16:56:19 -0400 | [diff] [blame] | 234 | linkgit:git-config[1] (e.g., `core.eol=true`). If multiple |
| 235 | values are given for the same key, each value will be written to |
| 236 | the config file. This makes it safe, for example, to add |
| 237 | additional fetch refspecs to the origin remote. |
SZEDER Gábor | 7eae4a3 | 2018-11-14 11:46:20 +0100 | [diff] [blame] | 238 | + |
| 239 | Due to limitations of the current implementation, some configuration |
| 240 | variables do not take effect until after the initial fetch and checkout. |
| 241 | Configuration variables known to not take effect are: |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 242 | ++remote.++__<name>__++.mirror++ and ++remote.++__<name>__++.tagOpt++. Use the |
SZEDER Gábor | 7eae4a3 | 2018-11-14 11:46:20 +0100 | [diff] [blame] | 243 | corresponding `--mirror` and `--no-tags` options instead. |
Jeff King | 84054f7 | 2011-06-09 16:56:19 -0400 | [diff] [blame] | 244 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 245 | `--depth` _<depth>_:: |
Junio C Hamano | f4bf218 | 2007-01-01 15:08:06 -0800 | [diff] [blame] | 246 | Create a 'shallow' clone with a history truncated to the |
Sebastian Schuberth | fc14281 | 2016-01-08 10:18:21 +0100 | [diff] [blame] | 247 | specified number of commits. Implies `--single-branch` unless |
Sebastian Schuberth | 28a1b56 | 2016-01-06 14:06:47 +0100 | [diff] [blame] | 248 | `--no-single-branch` is given to fetch the histories near the |
Junio C Hamano | 18a74a0 | 2016-06-19 13:51:56 -0700 | [diff] [blame] | 249 | tips of all branches. If you want to clone submodules shallowly, |
| 250 | also pass `--shallow-submodules`. |
Junio C Hamano | f4bf218 | 2007-01-01 15:08:06 -0800 | [diff] [blame] | 251 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 252 | ++--shallow-since=++__<date>__:: |
Nguyễn Thái Ngọc Duy | 994c2aa | 2016-06-12 17:54:00 +0700 | [diff] [blame] | 253 | Create a shallow clone with a history after the specified time. |
| 254 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 255 | ++--shallow-exclude=++__<revision>__:: |
Nguyễn Thái Ngọc Duy | 859e5df | 2016-06-12 17:54:05 +0700 | [diff] [blame] | 256 | Create a shallow clone with a history, excluding commits |
| 257 | reachable from a specified remote branch or tag. This option |
| 258 | can be specified multiple times. |
| 259 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 260 | `--`[`no-`]`single-branch`:: |
Nguyễn Thái Ngọc Duy | 3e6e0ed | 2012-01-07 21:45:59 +0700 | [diff] [blame] | 261 | Clone only the history leading to the tip of a single branch, |
| 262 | either specified by the `--branch` option or the primary |
Sebastian Schuberth | 28a1b56 | 2016-01-06 14:06:47 +0100 | [diff] [blame] | 263 | branch remote's `HEAD` points at. |
Ralf Thielow | 31b808a | 2012-09-20 20:04:08 +0200 | [diff] [blame] | 264 | Further fetches into the resulting repository will only update the |
Matthieu Moy | a6d3bde | 2012-10-23 13:34:05 +0200 | [diff] [blame] | 265 | remote-tracking branch for the branch this option was used for the |
Jean-Noël Avila | d3717e1 | 2024-03-10 19:10:29 +0000 | [diff] [blame] | 266 | initial cloning. If the `HEAD` at the remote did not point at any |
Matthieu Moy | a6d3bde | 2012-10-23 13:34:05 +0200 | [diff] [blame] | 267 | branch when `--single-branch` clone was made, no remote-tracking |
Ralf Thielow | 31b808a | 2012-09-20 20:04:08 +0200 | [diff] [blame] | 268 | branch is created. |
Nguyễn Thái Ngọc Duy | 3e6e0ed | 2012-01-07 21:45:59 +0700 | [diff] [blame] | 269 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 270 | `--no-tags`:: |
Ævar Arnfjörð Bjarmason | 0dab246 | 2017-04-26 23:12:33 +0000 | [diff] [blame] | 271 | Don't clone any tags, and set |
| 272 | `remote.<remote>.tagOpt=--no-tags` in the config, ensuring |
| 273 | that future `git pull` and `git fetch` operations won't follow |
| 274 | any tags. Subsequent explicit tag fetches will still work, |
| 275 | (see linkgit:git-fetch[1]). |
| 276 | + |
| 277 | Can be used in conjunction with `--single-branch` to clone and |
| 278 | maintain a branch with no references other than a single cloned |
| 279 | branch. This is useful e.g. to maintain minimal clones of the default |
| 280 | branch of some repository for search indexing. |
| 281 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 282 | `--recurse-submodules`[`=`{empty}__<pathspec>__]:: |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 283 | After the clone is created, initialize and clone submodules |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 284 | within based on the provided _<pathspec>_. If no _=<pathspec>_ is |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 285 | provided, all submodules are initialized and cloned. |
Stefan Beller | bc29b0b | 2017-12-04 18:53:32 -0800 | [diff] [blame] | 286 | This option can be given multiple times for pathspecs consisting |
| 287 | of multiple entries. The resulting clone has `submodule.active` set to |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 288 | the provided pathspec, or "." (meaning all submodules) if no |
Stefan Beller | bc29b0b | 2017-12-04 18:53:32 -0800 | [diff] [blame] | 289 | pathspec is provided. |
| 290 | + |
| 291 | Submodules are initialized and cloned using their default settings. This is |
| 292 | equivalent to running |
| 293 | `git submodule update --init --recursive <pathspec>` immediately after |
| 294 | the clone is finished. This option is ignored if the cloned repository does |
| 295 | not have a worktree/checkout (i.e. if any of `--no-checkout`/`-n`, `--bare`, |
| 296 | or `--mirror` is given) |
Johan Herland | e7fed18 | 2009-08-20 01:07:43 +0200 | [diff] [blame] | 297 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 298 | `--`[`no-`]`shallow-submodules`:: |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 299 | All submodules which are cloned will be shallow with a depth of 1. |
| 300 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 301 | `--`[`no-`]`remote-submodules`:: |
Jean-Noël Avila | fd5041e | 2019-12-12 21:46:54 +0100 | [diff] [blame] | 302 | All submodules which are cloned will use the status of the submodule's |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 303 | remote-tracking branch to update the submodule, rather than the |
Jean-Noël Avila | fd5041e | 2019-12-12 21:46:54 +0100 | [diff] [blame] | 304 | superproject's recorded SHA-1. Equivalent to passing `--remote` to |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 305 | `git submodule update`. |
| 306 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 307 | `--separate-git-dir=`{empty}__<git-dir>__:: |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 308 | Instead of placing the cloned repository where it is supposed |
| 309 | to be, place the cloned repository at the specified directory, |
Øystein Walle | 5fe8f49 | 2014-02-05 23:19:43 +0100 | [diff] [blame] | 310 | then make a filesystem-agnostic Git symbolic link to there. |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 311 | The result is Git repository can be separated from working |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 312 | tree. |
| 313 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 314 | `--ref-format=`{empty}__<ref-format>__:: |
Patrick Steinhardt | 5ed860f | 2023-12-29 08:27:09 +0100 | [diff] [blame] | 315 | |
| 316 | Specify the given ref storage format for the repository. The valid values are: |
| 317 | + |
| 318 | include::ref-storage-format.txt[] |
| 319 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 320 | `-j` _<n>_:: |
| 321 | `--jobs` _<n>_:: |
Stefan Beller | 72290d6 | 2016-02-29 18:07:20 -0800 | [diff] [blame] | 322 | The number of submodules fetched at the same time. |
| 323 | Defaults to the `submodule.fetchJobs` option. |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 324 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 325 | _<repository>_:: |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 326 | The (possibly remote) _<repository>_ to clone from. See the |
Todd Zullinger | 73364e4 | 2018-04-19 13:32:30 -0400 | [diff] [blame] | 327 | <<URLS,GIT URLS>> section below for more information on specifying |
Andrew Ruder | 37ba056 | 2007-07-04 17:21:36 -0500 | [diff] [blame] | 328 | repositories. |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 329 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 330 | _<directory>_:: |
Uwe Zeisberger | fb6a9f9 | 2006-06-08 08:50:09 +0200 | [diff] [blame] | 331 | The name of a new directory to clone into. The "humanish" |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 332 | part of the source repository is used if no _<directory>_ is |
Björn Gustavsson | 550c66f | 2009-10-20 22:38:38 +0200 | [diff] [blame] | 333 | explicitly given (`repo` for `/path/to/repo.git` and `foo` |
| 334 | for `host.xz:foo/.git`). Cloning into an existing directory |
Alexander Potashev | ec00d6e | 2009-05-07 16:04:08 +0400 | [diff] [blame] | 335 | is only allowed if the directory is empty. |
Junio C Hamano | 4607166 | 2005-11-05 22:26:52 -0800 | [diff] [blame] | 336 | |
Jean-Noël Avila | 76880f0 | 2024-03-29 11:19:40 +0000 | [diff] [blame] | 337 | `--bundle-uri=`{empty}__<uri>__:: |
Derrick Stolee | 5556891 | 2022-08-09 13:11:41 +0000 | [diff] [blame] | 338 | Before fetching from the remote, fetch a bundle from the given |
Jean-Noël Avila | 45d5ed3 | 2024-03-10 19:10:30 +0000 | [diff] [blame] | 339 | _<uri>_ and unbundle the data into the local repository. The refs |
Derrick Stolee | 5556891 | 2022-08-09 13:11:41 +0000 | [diff] [blame] | 340 | in the bundle will be stored under the hidden `refs/bundle/*` |
Derrick Stolee | e21e663 | 2022-08-09 13:11:43 +0000 | [diff] [blame] | 341 | namespace. This option is incompatible with `--depth`, |
| 342 | `--shallow-since`, and `--shallow-exclude`. |
Derrick Stolee | 5556891 | 2022-08-09 13:11:41 +0000 | [diff] [blame] | 343 | |
Sergei Organov | 347989f | 2007-11-16 21:43:16 +0300 | [diff] [blame] | 344 | :git-clone: 1 |
Andrew Ruder | 37ba056 | 2007-07-04 17:21:36 -0500 | [diff] [blame] | 345 | include::urls.txt[] |
| 346 | |
Nguyễn Thái Ngọc Duy | 76a8788 | 2018-04-30 17:35:33 +0200 | [diff] [blame] | 347 | EXAMPLES |
sean | 2b5f3ed | 2006-05-05 15:05:10 -0400 | [diff] [blame] | 348 | -------- |
Junio C Hamano | 1e2ccd3 | 2005-12-12 23:24:06 -0800 | [diff] [blame] | 349 | |
Michael J Gruber | 4763868 | 2010-03-21 18:30:19 +0100 | [diff] [blame] | 350 | * Clone from upstream: |
Junio C Hamano | 1e2ccd3 | 2005-12-12 23:24:06 -0800 | [diff] [blame] | 351 | + |
| 352 | ------------ |
W. Trevor King | 283efb0 | 2013-06-22 10:46:27 -0400 | [diff] [blame] | 353 | $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux |
| 354 | $ cd my-linux |
Junio C Hamano | 1e2ccd3 | 2005-12-12 23:24:06 -0800 | [diff] [blame] | 355 | $ make |
| 356 | ------------ |
| 357 | |
| 358 | |
Michael J Gruber | 4763868 | 2010-03-21 18:30:19 +0100 | [diff] [blame] | 359 | * Make a local clone that borrows from the current directory, without checking things out: |
Junio C Hamano | 1e2ccd3 | 2005-12-12 23:24:06 -0800 | [diff] [blame] | 360 | + |
| 361 | ------------ |
| 362 | $ git clone -l -s -n . ../copy |
Steffen Prohaska | a6e3768 | 2007-05-12 13:32:34 +0200 | [diff] [blame] | 363 | $ cd ../copy |
Junio C Hamano | 1e2ccd3 | 2005-12-12 23:24:06 -0800 | [diff] [blame] | 364 | $ git show-branch |
| 365 | ------------ |
| 366 | |
Junio C Hamano | 8a1a120 | 2006-01-14 16:00:32 -0800 | [diff] [blame] | 367 | |
Michael J Gruber | 4763868 | 2010-03-21 18:30:19 +0100 | [diff] [blame] | 368 | * Clone from upstream while borrowing from an existing local directory: |
Shawn Pearce | 23edecb | 2006-04-18 20:19:48 -0400 | [diff] [blame] | 369 | + |
| 370 | ------------ |
W. Trevor King | f22a654 | 2013-06-22 10:46:25 -0400 | [diff] [blame] | 371 | $ git clone --reference /git/linux.git \ |
| 372 | git://git.kernel.org/pub/scm/.../linux.git \ |
| 373 | my-linux |
| 374 | $ cd my-linux |
Shawn Pearce | 23edecb | 2006-04-18 20:19:48 -0400 | [diff] [blame] | 375 | ------------ |
| 376 | |
| 377 | |
Michael J Gruber | 4763868 | 2010-03-21 18:30:19 +0100 | [diff] [blame] | 378 | * Create a bare repository to publish your changes to the public: |
Junio C Hamano | 8a1a120 | 2006-01-14 16:00:32 -0800 | [diff] [blame] | 379 | + |
| 380 | ------------ |
Junio C Hamano | 87e80c4 | 2006-01-22 17:24:22 -0800 | [diff] [blame] | 381 | $ git clone --bare -l /home/proj/.git /pub/scm/proj.git |
Junio C Hamano | 8a1a120 | 2006-01-14 16:00:32 -0800 | [diff] [blame] | 382 | ------------ |
| 383 | |
Ævar Arnfjörð Bjarmason | 16f6b0d | 2022-09-07 10:27:04 +0200 | [diff] [blame] | 384 | CONFIGURATION |
| 385 | ------------- |
| 386 | |
| 387 | include::includes/cmd-config-section-all.txt[] |
| 388 | |
Ævar Arnfjörð Bjarmason | 9274dea | 2022-09-07 10:27:05 +0200 | [diff] [blame] | 389 | include::config/init.txt[] |
| 390 | |
Ævar Arnfjörð Bjarmason | 16f6b0d | 2022-09-07 10:27:04 +0200 | [diff] [blame] | 391 | include::config/clone.txt[] |
| 392 | |
Junio C Hamano | 8a1a120 | 2006-01-14 16:00:32 -0800 | [diff] [blame] | 393 | |
Junio C Hamano | 6ec311d | 2005-07-13 20:25:54 -0700 | [diff] [blame] | 394 | GIT |
| 395 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 396 | Part of the linkgit:git[1] suite |