Git Clone
In short
Git clone is a Git command that downloads a complete copy of an existing repository, including its full history, and sets it up on your computer for work.
What is git clone?
git clone is usually the first command you run when you join a project. Given a URL, it creates a new folder, downloads every commit and branch from the remote repository, and checks out the default branch, usually main, so the files appear on disk. The result is a complete, independent repository with the entire history, not just a copy of the latest files.
Behind the scenes, cloning also sets up a Git remote named origin that points back to the URL, plus remote-tracking branches such as origin/main that record where each remote branch was at the time. Your local main is configured to track origin/main, which is why a plain git pull or git push works right away. Repositories can be cloned over HTTPS, where private projects ask for a token or stored credentials, or over SSH, which authenticates with a key pair.
Cloning is like photocopying an entire filing cabinet, archive boxes included, rather than borrowing a single folder. For very large repositories you can copy less: a shallow clone with --depth 1 downloads only the latest commit, and a partial clone with --filter=blob:none fetches file contents only when they are needed. Shallow clones are common in CI pipelines, where only the current code matters.
Clone is often confused with fork and with pull. A fork is a copy of a repository made on a hosting platform under your own account, and you usually clone your fork afterward to work on it locally. You clone a repository once, while git pull is what you run again and again afterward to bring in new commits.
Key takeaways
git clone <url>copies a repository, with its full history, to your machine.- It automatically adds a remote named
originand checks out the default branch. - Every clone is a complete repository that can be used offline.
- Shallow (
--depth 1) and partial (--filter=blob:none) clones download less data. - You clone once; afterward you use
git pullto stay up to date.
Example
# Copy a repository into a new folder named after it
git clone https://github.com/example/my-project.git
# Clone over SSH into a folder with a different name
git clone git@github.com:example/my-project.git work-copy
# Clone only the latest commit (faster, common in CI)
git clone --depth 1 https://github.com/example/my-project.git ci-copy
# Look inside a clone: origin points back to the source URL
cd work-copy
git remote -v
git branch -a # local main plus remote-tracking branchesReaders ask
What is the difference between git clone and git pull?
git clone creates a brand-new local repository from a remote one and is run once. git pull updates a repository you already have by fetching new commits from its remote and merging them into your current branch.
What is the difference between cloning and forking?
Cloning copies a repository to your computer. Forking copies it to your own account on a hosting platform, and people often fork a project first and then clone their fork.
How do I clone a specific branch?
Use git clone --branch <name> <url> to check out that branch right after cloning. Add --single-branch if you want Git to download only that branch's history.
See also
- RepositoryVersion Control, p. 34A repository is the storage location for a project, holding all of its files plus the complete history of every change recorded by a version control system.
- ForkVersion Control, p. 9A fork is a personal copy of someone else's repository on a hosting platform, letting you experiment freely and propose changes back to the original project.
- Git RemoteVersion Control, p. 19A Git remote is a named shortcut, such as origin, to another copy of your repository, usually on a server, that you push commits to and pull commits from.
- Git PullVersion Control, p. 17Git pull is a Git command that downloads new commits from a remote repository and immediately integrates them into your current local branch.
- Git PushVersion Control, p. 18Git push is a Git command that uploads your local commits to a remote repository, updating the matching branch there so others can see and use your work.
- GitVersion Control, p. 10Git is a free, open-source distributed version control system that tracks changes to files over time, so developers can collaborate and undo mistakes.
Spotted a mistake or something missing on this page?Suggest an edit