Terminal GuideTerminal Guide

git clone Command Guide

Clone a repository into a new directory

5 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git clone <url>Clone repository
git clone <url> <dir>Clone to directory
git clone -b <branch> <url>Clone specific branch

Shallow

--depth 1Shallow clone (latest only)
--shallow-since=<date>Clone since date
--single-branchClone single branch

Options

--recurse-submodulesInclude submodules
--bareClone as bare repo
--mirrorMirror the repository

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git clone command creates a copy of an existing Git repository. It downloads all files, branches, and commit history.

bash
# Clone a repository
git clone https://github.com/user/repo.git

# Clone into a specific directory
git clone https://github.com/user/repo.git my-folder

# Clone a specific branch
git clone -b develop https://github.com/user/repo.git

Clone Protocols

Git supports several protocols for cloning:

bash
# HTTPS (most common, works through firewalls)
git clone https://github.com/user/repo.git

# SSH (requires SSH key setup)
git clone git@github.com:user/repo.git

# Git protocol (read-only, no authentication)
git clone git://github.com/user/repo.git

# Local path
git clone /path/to/local/repo
git clone file:///path/to/local/repo
Tip
Use SSH for repositories you push to frequently. Set up SSH keys once and never enter passwords again.

Common Options

OptionDescription
-b <branch>Clone a specific branch
--depth <n>Create a shallow clone with n commits
--single-branchClone only one branch
--recurse-submodulesInitialize and clone submodules
--bareClone as a bare repository
--mirrorCreate a mirror (all refs)

Shallow Clones

Shallow clones download only recent history, useful for large repositories:

bash
# Clone only the latest commit
git clone --depth 1 https://github.com/user/repo.git

# Clone with limited history
git clone --depth 10 https://github.com/user/repo.git

# Clone since a specific date
git clone --shallow-since="2024-01-01" https://github.com/user/repo.git

# Shallow clone of single branch
git clone --depth 1 --single-branch -b main https://github.com/user/repo.git

# Convert shallow to full clone later
git fetch --unshallow

Practical Examples

bash
# Basic clone and start working
git clone https://github.com/user/repo.git
cd repo

# Clone for CI/CD (fast, minimal)
git clone --depth 1 --single-branch https://github.com/user/repo.git

# Clone with all submodules
git clone --recurse-submodules https://github.com/user/repo.git

# Clone specific branch for feature work
git clone -b feature-branch https://github.com/user/repo.git

# Mirror a repository for backup
git clone --mirror https://github.com/user/repo.git

# Clone to a different folder name
git clone https://github.com/user/repo.git my-project

Frequently Asked Questions

What is the difference between HTTPS and SSH clone URLs?

HTTPS is simpler and works through firewalls but requires entering credentials. SSH uses key-based authentication and is more convenient once set up, especially for frequent pushes.

How do I clone a specific branch?

Use "git clone -b <branch-name> <url>" to clone a specific branch. Add --single-branch to only fetch that branch's history.

What is a shallow clone?

A shallow clone (--depth) only downloads recent history, not the entire repository history. This is faster and uses less disk space, useful for CI/CD or large repositories.

How do I clone a repository with submodules?

Use "git clone --recurse-submodules <url>" to clone the repository and all its submodules. For existing clones, run "git submodule update --init --recursive".

Can I clone a private repository?

Yes, you need proper authentication. For HTTPS, you'll be prompted for credentials (or use a personal access token). For SSH, you need your SSH key added to the remote service.

Summary

git clone is how you get a copy of a repository. Use shallow clones for speed, SSH for convenience, and remember submodules if needed.

Quick Reference

  • git clone <url> - Clone repository
  • git clone -b <branch> - Clone specific branch
  • git clone --depth 1 - Shallow clone
  • git clone --recurse-submodules - Include submodules

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles