How to Clone a Git Repository (Including Shallow Clones)
Cloning downloads an existing Git repository to your local computer, giving you a full local copy of the project — including its complete history — ready to work on.
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
Tip
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.
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.