Skip to main content

Git Clone

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/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 origin and 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 pull to stay up to date.

Example

Cloning a repository in different waysbash
# 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 branches

Readers 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

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings