git clone
git
Syntaxe
git clone [--depth <n>] [-b <branch>] <url> [<directory>]Copie un dépôt distant avec son historique ; un clone --depth 1 n'a ni anciens commits ni autres branches, d'où --unshallow plus tard.
Options courantes
| Option | Signification |
|---|---|
| --depth <n> | shallow copy with only the last n commits |
| -b <branch> | check out that branch instead of the default |
| --single-branch | fetch one branch only |
| --recurse-submodules | clone submodules at the same time |
| --filter=blob:none | partial clone: fetch file contents on demand |
| -o <name> | call the remote something other than origin |
Exemples
git clone https://github.com/user/repo.gitcopies the repository into repo/ and names the remote origin
git clone --depth 1 https://github.com/user/repo.gitfast copy for CI with no old history
git clone -b dev --single-branch <url>checks out dev and fetches nothing else
Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait git clone ?
Copie un dépôt distant avec son historique ; un clone --depth 1 n'a ni anciens commits ni autres branches, d'où --unshallow plus tard.
Q. Comment l’écrire ?
git clone [--depth <n>] [-b <branch>] <url> [<directory>] — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 6 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-clone