How to Clone a Git Repository (Including Shallow Clones)
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!
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.
Download the Cheat SheetFree
Get 18 of our most popular Cheat Sheets in one handy ZIP!

Thanks! Please Check Your Inbox!
Want to win one of our awesome Tower shirts?
Tell your friends about the package!
