Every collaborative coding project starts the same way: someone clones a repository. But what is git clone, really, and why does it matter beyond just downloading files?
Git clone is the command that copies an entire remote repository to your local machine, including every branch, commit, and configuration file. It is the first step in nearly every development workflow, whether you are contributing to open source on GitHub or setting up a CI/CD pipeline.
This article breaks down how the clone command works, its syntax and flags, the difference between cloning and forking, shallow and partial clone strategies, and how to troubleshoot the most common errors developers run into across GitHub, GitLab, and Bitbucket.
What is Git Clone

Git clone is a command in Git that creates a complete local copy of a remote repository. It downloads every file, every branch, every tag, and the full commit history onto your machine.
Think of it as the starting point for almost any collaborative project. You find a repository on GitHub, GitLab, or Bitbucket, and you run one command to get your own working copy.
The basic syntax looks like this:
git clone <repository-url>
That single line pulls down the entire codebase, sets up a .git directory, and configures a remote tracking connection called origin pointing back to the source URL. Your local copy is fully functional right away.
The Stack Overflow Developer Survey found that 93% of developers use Git as their primary version control system. And cloning is typically the very first Git operation any developer runs when joining a project or contributing to open source code.
One thing worth calling out: cloning is not the same as downloading a ZIP file from a repository page. A ZIP gives you a snapshot of the source code at one point in time. A clone gives you the entire history. Every commit, every change, every branch that ever existed.
That distinction matters. With a clone, you can check out previous versions, create new branches, and push your own changes back to the remote. A ZIP file lets you do none of that.
How Git Clone Works

When you execute git clone, Git performs several operations behind the scenes. It is not just a file download. It is a full reconstruction of a distributed repository on your local machine.
What Happens Step by Step
First, Git creates a new directory named after the repository (unless you specify a different one). Inside that directory, it initializes a .git folder that stores all the metadata, objects, and configuration.
Then it contacts the remote server and downloads every reachable object. That includes commits, trees, blobs, and annotated tags.
Finally, it checks out the default branch (usually main or master) as your working copy. At this point, your local directory mirrors the latest state of the project.
Key detail: Git also sets up a remote reference called origin. This is just a shorthand label pointing to the URL you cloned from. When you later run git fetch or git pull, Git knows where to look for updates because of this reference.
What Gets Copied During a Clone
Included in the clone:
- Full commit history across all branches
- All tags and annotated tag objects
- Remote tracking branch configuration
- Repository-level Git config settings
Not included:
- Server-side hooks and CI/CD pipeline configs that live outside the repo
- GitHub-specific settings like branch protection rules, issues, or pull request data
- Platform features such as GitHub Actions workflow run history
The Linux kernel repository, one of the largest open-source Git repos out there, contains over 1.5 million commits and totals 10 to 15 GB with full history. Cloning something that big makes the distinction between “what gets copied” and “what stays on the server” very real.
Git Clone Command Syntax and Options

The basic form is straightforward. But git clone supports a bunch of flags that change what gets downloaded and how the local repo is configured.
git clone [options] <repository-url> [directory]
Here is a look at the most commonly used options and when you would reach for each one.
| Flag | What It Does | When to Use It |
|---|---|---|
| –branch / -b | Checks out a specific branch or tag | Working on a feature branch directly |
| –depth | Limits the number of commits fetched | CI/CD pipelines, quick inspections |
| –single-branch | Fetches only one branch instead of all | Saving bandwidth on large repos |
| –recurse-submodules | Also clones any Git submodules | Projects with nested dependencies |
| –bare | Creates a bare repository with no working directory | Server-side mirrors and backups |
I’ve seen teams waste minutes per build just because nobody thought to pass --depth 1 in their pipeline config. Small flag, big impact.
HTTPS vs SSH Clone URLs
Every time you clone, you pick a protocol. The two main options are HTTPS and SSH, and they work differently under the hood.
HTTPS cloning uses token-based authentication. GitHub shows HTTPS as the default option when you click “Clone” on a repository page. It works through port 443, which almost never gets blocked by firewalls. For beginners or quick public-repo access, it is the path of least resistance.
SSH cloning uses key-based authentication. You generate an SSH key pair, add your public key to GitHub, and from that point forward you never enter credentials for push or pull operations. Most experienced developers end up preferring this approach for day-to-day work.
If you cloned with HTTPS but later want SSH (or the other way around), you can switch without re-cloning:
git remote set-url origin git@github.com:user/repo.git
Each hosting platform formats its URLs a bit differently. GitHub, GitLab, and Bitbucket all follow the same general pattern, but the domain and path structure vary. The GitHub CLI even offers a shortcut: gh repo clone owner/repo, which skips the URL entirely.
Git Clone vs Git Fork vs Git Pull
These three operations get confused constantly. Took me a while to get them straight too, honestly. They overlap in purpose but do very different things.
Clone vs Fork

Clone copies a remote repository to your local machine. That is a core Git command that works with any hosting platform.
Fork creates a server-side copy of a repository under your own account. It is not a Git command at all. It is a feature provided by GitHub, GitLab, and similar platforms.
In open-source workflows, these two go hand in hand. You fork a project on GitHub to get your own copy in the cloud, then clone that fork to your local machine. After making changes, you push to your fork and open a pull request to the original project.
Clone vs Pull vs Fetch
| Operation | Purpose | When to Use |
|---|---|---|
| git clone | First-time copy of an entire remote repository | Starting work on a new project |
| git pull | Fetches updates and merges them into your current branch | Syncing with teammates’ changes |
| git fetch | Downloads updates without merging anything | Reviewing remote changes before integrating |
Clone is something you run once per repository. Pull and fetch are things you run regularly after that. If your local copy already exists, running clone again would just create a duplicate directory.
According to GitHub, over 150 million developers used the platform by 2025, with more than 5 billion contributions recorded across public and private repositories in 2024. Most of those contributions started with a clone or a fork.
Shallow Clone and Partial Clone

Cloning the full history of a large repository takes time, bandwidth, and disk space. Sometimes you don’t need any of that history. You just want the latest code.
That is where shallow clones and partial clones come in.
What is a Shallow Clone
A shallow clone uses the --depth flag to limit how many commits Git downloads.
git clone --depth 1 https://github.com/owner/repo.git
This gives you only the most recent commit and the current working tree. No prior history. No older branches. Just the tip of the default branch.
GitHub’s own data-driven study on cloning behaviors found that shallow clones are the fastest clone type for the client. For a project like the Linux kernel, a shallow clone can be four times faster than a full clone.
GitHub Actions uses shallow clones by default, with fetch-depth: 1 in the checkout action. That is a solid indicator of how common this pattern has become in continuous integration setups.
What is a Partial Clone
Partial clones take a different approach. Instead of cutting off history by commit count, they filter by object type.
Blobless clone: git clone --filter=blob:none <url> downloads all commits and trees but skips the actual file content until you need it. Good when you want full commit history but the repo has large binary files.
Treeless clone: git clone --filter=tree:0 <url> fetches only commit objects. Trees and blobs get downloaded on demand. Faster than blobless, but more dependent on network access.
Tradeoffs and When to Use Each
Shallow clones break certain Git commands. Running git blame or git bisect on a shallow clone will fail or return incomplete results because the history is simply not there.
You can always “unshallow” later with git fetch --unshallow, which pulls the missing history. But at that point, you might as well have done a full clone from the start.
Rule of thumb: use shallow clones for build pipelines and throwaway builds. Use partial clones when you want history access but are working in a monorepo with large assets. Use full clones for active development where you need git log, blame, and rebase.
Cloning Large Repositories

Standard git clone works fine for most projects. But once a repository crosses a few gigabytes, things get tricky. Clone times spike, network connections time out, and disk space becomes a real issue.
RhodeCode data shows Git adoption reached 93.87% in 2025, up from 87.1% in 2016. As more teams centralize on Git, the repos keep growing.
The Monorepo Problem
Companies like Google, Microsoft, and Meta store massive amounts of code in single repositories. Microsoft’s Windows codebase alone was famously too large for standard Git operations, which led to the creation of VFS for Git (now called Scalar).
For most teams, the fix starts with smart source control practices and the clone flags covered earlier. Shallow clones, partial clones, and sparse checkouts all help reduce the initial download.
Git LFS and Binary Assets
Git was built for text files. Binary assets like images, videos, design files, and compiled artifacts bloat the repository fast because Git can’t delta-compress them the way it does code.
Git LFS (Large File Storage) solves this by replacing large files with lightweight pointer files in the repo. The actual content lives on a separate LFS server and gets downloaded only when checked out.
When cloning an LFS-enabled repo, you may need to run git lfs pull after clone, or use git lfs clone to handle everything in one step.
Sparse Checkout for Subdirectory Access
Sometimes you just need one folder from a massive repo. Sparse checkout combined with a partial clone lets you do exactly that.
“ git clone --filter=blob:none --sparse https://github.com/big-org/monorepo.git cd monorepo git sparse-checkout set path/to/my-service `
Now your working directory contains only the files in path/to/my-service, while the rest of the repo structure exists as lightweight references.
Handling Network Issues
Large clones over slow or unstable connections often fail with errors like RPC failed; curl transfer closed with outstanding read data remaining.
A few things that help:
- Increase the HTTP buffer: git config –global http.postBuffer 524288000
- Clone over SSH instead of HTTPS for better connection stability
- Use –depth 1
first, then deepen gradually withgit fetch –deepen=100
The GitHub Blog’s study on cloning behaviors noted that performance impact scales directly with repository size, particularly the number of commits. A shallow clone of the Linux kernel repo finishes four times faster than a full clone. That speed difference matters even more in continuous deployment pipelines that clone on every build.
Git Clone in Common Workflows

Cloning is not just a “getting started” step. It shows up in automated pipelines, open-source contributions, backup strategies, and team onboarding. Where and how you clone changes depending on what you are actually trying to do.
Open-Source Contributions
The standard pattern for contributing to an open-source project goes like this: fork the repository on GitHub or GitLab, then clone your fork locally.
From there, you create a new branch, make your changes, commit them, and push to your fork. The pull request goes from your fork back to the original project.
GitHub data shows over 413 million open-source contributions were made on the platform in 2022 alone. Most of those started with a clone.
Cloning Inside CI/CD Pipelines
GitHub Actions runs over 5 million workflows daily, according to GitHub’s 2025 data. Every single one of those workflows starts with some form of repository clone.
Default behavior: the actions/checkout step performs a shallow clone with fetch-depth: 1. That is fast, but it strips away commit history. If your pipeline needs tags for versioning or commit messages for changelogs, you have to override the depth.
A JetBrains survey found that 62% of developers use GitHub Actions for personal projects and 41% use it in organizations. Jenkins and GitLab CI remain popular at the enterprise level, but the clone step works roughly the same everywhere.
Mirror Cloning for Backups and Migrations
The –mirror flag creates an exact copy of a repository, including all refs, branches, tags, and configuration.
git clone –mirror https://github.com/org/repo.git
Common uses:
- Moving a repository from GitHub to GitLab (or the other way around)
- Creating an offline backup of a critical software system
- Setting up a local read-only reference for teams behind restricted networks
Template Repositories and Boilerplate Projects
Cloning a template repo is one of the fastest ways to start a new project. GitHub, GitLab, and Bitbucket all support template repositories that act as starting points.
You clone the template, remove the .git directory, run git init to create a fresh history, and start building. It is basically how most rapid app development workflows kick off these days.
Troubleshooting Git Clone Errors

Git clone fails more often than most people expect. Wrong URLs, broken SSH configs, network timeouts. The error messages are sometimes helpful, sometimes not.
Here are the errors that come up the most, and how to fix them.
Repository Not Found
fatal: repository ‘https://github.com/user/repo.git/’ not found
Causes and fixes:
- Typo in the URL: always copy the clone link directly from the repository page
- Private repo without access: confirm you’ve been added as a collaborator
- Wrong account authenticated: check which credentials Git is using with git credential-manager list
GitHub’s troubleshooting docs note that this is the single most common clone error. Usually it is just a wrong URL or missing permissions.
Permission Denied (publickey)
git@github.com: Permission denied (publickey).
This one trips up a lot of developers. It means your SSH key either does not exist, is not loaded into the SSH agent, or is not added to your hosting platform.
Quick checklist:
- Run ssh -T git@github.com
to test the connection
- Check that your key exists: ls ~/.ssh/ided25519.pub
- Make sure the agent is running: eval “$(ssh-agent -s)”
If SSH feels like too much hassle, switching to HTTPS with a personal access token is a perfectly fine alternative. You can learn how to get a GitHub token and use it in place of a password.
RPC Failed and Transfer Errors
error: RPC failed; curl 56 GnuTLS recv error
This typically happens when cloning large repositories over unstable network connections. The HTTP buffer runs out of space, or the connection drops mid-transfer.
| Fix | Command | When to Use |
|---|---|---|
| Increase HTTP buffer | git config –global http.postBuffer 524288000 | Large repos over HTTPS |
| Switch to SSH | git clone git@github.com:user/repo.git | Better connection handling |
| Shallow clone first | git clone –depth 1 | Very large repos, slow connections |
The GitHub Blog notes that clone performance scales directly with repository size. For a repository like the Linux kernel (over 1.5 million commits), a full clone over a weak connection will almost certainly hit this error.
SSL Certificate Errors
SSL certificate problem: unable to get local issuer certificate
Corporate networks and VPNs often intercept HTTPS traffic with custom certificates that Git does not recognize. The quick workaround is git config –global http.sslVerify false, but that disables certificate verification entirely.
Better approach: add your organization’s CA certificate to Git’s trusted bundle. Your IT team should be able to provide the certificate file, and you point Git to it with git config –global http.sslCAInfo /path/to/cert.pem.
GitHub reported that over 39 million secrets were leaked on the platform in 2024. Disabling SSL verification, even temporarily, increases the risk of credential interception. Handle this one carefully.
Git Clone with GitHub, GitLab, and Bitbucket
The git clone command works the same everywhere, but each hosting platform adds its own tooling, URL formats, and authentication methods on top. Knowing those differences saves time when you switch between platforms or manage repos across multiple providers.
More than 90% of Fortune 100 companies use GitHub in their development workflows, according to GitHub. GitLab has an estimated 30 million users, and Bitbucket serves about 15 million, mainly through Atlassian’s ecosystem.
Cloning on GitHub

GitHub offers the most cloning shortcuts of any platform. Beyond the standard HTTPS and SSH URLs, the GitHub CLI lets you skip the URL entirely:
gh repo clone owner/repo
This handles authentication automatically if you have already run gh auth login. It is the fastest way to clone from a terminal when you are already logged into GitHub.
Authentication options: personal access tokens, SSH keys, GitHub CLI tokens, and fine-grained tokens (introduced in 2022 for more granular repository access).
Cloning on GitLab
GitLab supports HTTPS and SSH like GitHub, but adds deploy tokens and job tokens for CI-specific cloning. These are purpose-built credentials that live outside of any individual developer’s account.
When a GitLab CI pipeline runs, it automatically receives a CIJOB_TOKEN that can clone other repositories within the same group. No manual credential setup needed, which is a nice touch for teams running multi-repo DevOps pipelines.
GitLab also introduced EU data residency for its SaaS product in 2024, which affects where cloned data physically travels during CI/CD runs.
Cloning on Bitbucket
Bitbucket is tightly integrated with the Atlassian stack (Jira, Confluence, Trello). The clone experience uses app passwords instead of personal access tokens, which is a Bitbucket-specific concept.
The clone URL appears on each repository’s landing page, same as GitHub and GitLab. But if your team uses Bitbucket Pipelines for CI/CD, the repository is cloned automatically at the start of each pipeline step with built-in authentication.
Switching Between Platforms
Moving a repository from one platform to another is just a mirror clone followed by a push to the new remote.
` git clone --mirror https://github.com/org/repo.git cd repo.git git push --mirror https://gitlab.com/org/repo.git `
That copies everything: all branches, all tags, all refs. The history is preserved completely.
After migration, update your git remote references and reconfigure any build pipelines that reference the old clone URL. Most teams forget this part, and their automated deployments break silently the next day.
FAQ on What Is Git Clone
What does git clone actually do?
Git clone creates a complete local copy of a remote repository. It downloads every file, branch, tag, and commit history, then sets up a remote reference called origin pointing back to the source URL.
What is the difference between git clone and git pull?
Git clone copies an entire repository for the first time. Git pull updates an existing local repository by fetching new changes from the remote and merging them into your current branch. Clone runs once, pull runs repeatedly.
Is git clone the same as downloading a ZIP file?
No. A ZIP download gives you a snapshot of the source code without any version control history. Git clone includes the full commit history, all branches, and the ability to push changes back to the remote.
How do I clone a specific branch?
Use the -b flag followed by the branch name: git clone -b branch-name . You can combine this with –single-branch to avoid downloading other branches and save bandwidth on large repositories.
Should I clone with HTTPS or SSH?
HTTPS is simpler to set up and works behind most firewalls. SSH uses key-based authentication and skips repeated credential prompts. Most experienced developers prefer SSH for daily work, while HTTPS works best for quick, one-off access.
What is a shallow clone in Git?
A shallow clone uses the –depth flag to download only a limited number of recent commits instead of the full history. It is faster and lighter, making it the go-to choice for CI/CD pipelines and automated builds.
Can I clone a private repository?
Yes, but you need proper authentication. Either configure an SSH key linked to your account or use an HTTPS URL with a personal access token. Without valid credentials, Git returns a “repository not found” error.
How do I clone a repository from GitHub using the command line?
Copy the clone URL from the repository page on GitHub. Open your terminal and run git clone . The GitHub CLI also offers a shortcut: gh repo clone owner/repo.
What does git clone –mirror do?
Mirror cloning creates a bare, exact copy of a repository including all refs and configuration. It is mainly used for repository backups and migrations between platforms like GitHub, GitLab, and Bitbucket.
Why is my git clone so slow?
Large repositories with extensive commit histories take longer to clone. Try a shallow clone with –depth 1 to speed things up. Switching from HTTPS to SSH or increasing the HTTP buffer size can also help on unstable connections.
Conclusion
Understanding what is git clone gives you the foundation for every Git-based workflow that follows. Without it, there is no local development, no branching, no pull requests.
Whether you are running a shallow clone inside a GitHub Actions pipeline or doing a full clone to dig through commit history with git log and git blame, the command adapts to your situation. Flags like –depth, –mirror, and –single-branch` exist for a reason. Use them.
Pick the right protocol. HTTPS for quick access, SSH for daily development. Know how to troubleshoot permission errors before they stall your work.
Clone is where distributed version control starts. Everything else, from fetch to merge to deployment, builds on top of that first local copy sitting on your machine.
- How to Make a Repository Public in GitHub - July 14, 2026
- Production Incident Communication Without Separate Monitoring and Status-Page Systems - July 13, 2026
- How to Set Up Subscriptions on Google Play (Developer Guide) - July 12, 2026



