About git clone command generator
git clone copies a repository to your computer. Options let you choose a branch or fetch only recent history to save time and disk space.
Useful options
- --branch picks a branch.
- --depth 1 makes a shallow clone with only the latest commit.
- --single-branch fetches just one branch.
- --recurse-submodules also fetches submodules.
A worked example
To get only the latest code of one branch from a huge repository, use git clone --depth 1 --single-branch --branch main <url>. That downloads a fraction of the data. Later, git fetch --unshallow restores the full history if you need it.
Other options
- --recurse-submodules fetches submodules at the same time.
- A folder name at the end sets where the repository is placed.
- SSH URLs avoid typing credentials for private repositories.
Authentication
Private repositories need credentials. Over HTTPS use a personal access token with a credential helper, or use an SSH URL with your key added to your account.
