How to Clone a Git Repository (Including Shallow Clones)
Short answer
To clone a Git repository, run git clone <url>, where the URL points to the remote repository. Git will download the full project history and create a local folder named after the repository. To use a different folder name, provide it as a second argument: git clone <url> <directory>. For repositories with submodules, add --recurse-submodules to clone and initialize them in one step. If you only need recent history — useful in CI/CD pipelines or with large repositories — use git clone --depth=1 <url> to fetch only the latest commit. You can later download more history with git fetch --deepen <number>, or convert to a full clone with git fetch --unshallow. Shallow clones have limitations: git bisect, git log --follow, and some rebase operations may not work correctly without the full history.
Run git clone <url> to download a full copy of a repository - history included - into a new local folder named after it.
That's the default. On a large repository, downloading the entire history can be slow; below is the --depth=1 shallow-clone option that fetches just the latest commit instead, plus what you lose (git bisect, git log --follow) by doing that.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Free. We email you a ZIP with our cheat sheets.
Basic Usage
In its simplest form, provide the repository URL and Git will create a local folder named after the repository:
git clone https://github.com/gittower/git-crash-course.git
To clone into a folder with a different name, specify it as a second argument:
git clone https://github.com/gittower/git-crash-course.git my-project
If the repository contains submodules, use --recurse-submodules to clone and initialize them all in one step:
git clone --recurse-submodules https://github.com/example/repo.git
No Command Line Needed
Cloning a Repository in Tower
In case you are using the Tower Git client, cloning a project becomes easy as pie. You can connect your GitHub / GitLab / Bitbucket / or other remote accounts with Tower — and from then on simply clone with a single click!
Shallow Clones
By default, git clone downloads the repository's complete history. For large repositories with long histories, this can be slow. A shallow clone fetches only the most recent commits, making the initial download significantly faster and smaller.
Creating a Shallow Clone
Use the --depth option to specify how many commits to fetch:
# Fetch only the latest commit (fastest)
$ git clone --depth 1 https://github.com/example/repo.git
# Fetch the last 10 commits
$ git clone --depth 10 https://github.com/example/repo.git
Shallow clones are ideal for CI/CD pipelines, where you need the current code quickly and don't need the full history for each build.
Expanding a Shallow Clone
If you need more history than you initially fetched, use --deepen:
# Add 50 more commits to your existing shallow clone
$ git fetch --deepen 50
To convert a shallow clone into a full clone with complete history:
git fetch --unshallow
Limitations
Shallow clones work well for most day-to-day tasks, but there are some operations that require the full history:
git bisect— relies on the complete commit history to find bugsgit log --follow— may miss renames outside the shallow boundary- Rebasing — operations involving commits outside the fetched history may fail
If you run into issues, deepen your clone or run git fetch --unshallow before the operation.