Par Anonyme (non vérifié) , 29 avril 2026

Synopsis

git clone [--branch <name>] [--depth <n>] [--recurse-submodules] <url> [directory]

Description

The git clone command copies an existing repository (typically from a remote server) into a new local directory. It performs three actions: it creates a new directory, runs git init inside it, and then fetches all branches and history from the remote. After cloning, the remote is automatically configured as origin, and the default branch is checked out into the working tree.

Cloning supports multiple protocols: HTTPS (most common, easiest with credential helpers), SSH (preferred for write access using key-based auth), and the legacy git:// protocol. For very large repositories, partial clones, shallow clones, and sparse checkouts can dramatically reduce the amount of data transferred.

Authentication is one of the most common stumbling blocks. With HTTPS, modern Git uses credential helpers (Keychain on macOS, Credential Manager on Windows, libsecret on Linux) to cache tokens or passwords securely. With SSH, your local SSH agent supplies the key — make sure ssh-add has loaded it. After cloning, git config --get remote.origin.url confirms what was actually configured. For monorepo or supercomputer-scale repositories, partial clone (--filter=blob:none) combined with sparse checkout (git sparse-checkout init --cone) lets you work with just a slice of the project, reducing both clone time and on-disk footprint dramatically. CI pipelines benefit further from --depth=1 and --no-tags when they don't need history.

Options courantes

OptionDescription
--branch <name> / -bFaire le checkout de la branche ou du tag nommé au lieu du défaut.
--depth <n>Créer un clone shallow avec un historique tronqué.
--single-branchCloner uniquement l'historique d'une seule branche.
--recurse-submodulesInitialiser et cloner les sous-modules immédiatement après le clone principal.
--filter=blob:noneCréer un clone partiel sans contenu blob (récupéré paresseusement à la demande).
--bareFaire un clone nu sans arborescence de travail.
--mirrorConfigurer un miroir avec toutes les refs, adapté aux sauvegardes.

Exemples

git clone https://github.com/user/project.git
# Clone standard via HTTPS

git clone [email protected]:user/project.git my-fork
# Clone via SSH dans un répertoire spécifique

git clone --depth 1 --branch v2.0 https://github.com/user/project.git
# Clone shallow d'un tag spécifique, utile pour la CI

git clone --filter=blob:none https://github.com/torvalds/linux.git
# Clone partiel pour énormes dépôts — blobs fetchés à la demande

Erreurs fréquentes

Cloning a giant repository without filters can take minutes or hours and consume gigabytes. For exploration or CI builds, prefer --depth 1. Another mistake is cloning over HTTPS when you intend to push changes — without credential setup, every push will prompt for a password. Use SSH or a credential helper for write access. Finally, be aware that --single-branch clones cannot easily access other branches without reconfiguring the remote.

Commandes liées

git init, git fetch, git remote, git submodule