git clone
Copy a repository into a new folder
The 'git clone' command downloads a repository — every commit, branch and tag — into a new folder, checks out its default branch, and remembers the address as the remote named origin. Your main tracks origin/main, so git pull and git push work straight away. With --depth you download only the latest commits.
Synopsis
git clone [<options>] <repository> [<directory>]Options
Choosing the Right Option
Full vs shallow
What gets downloaded
| Command | History | Best for |
|---|---|---|
git clone <url> | Everything | Daily work |
git clone --depth 1 <url> | Latest commit only | CI builds, quick look |
Examples
Clone with SSH
git clone git@github.com:acme/shop.gitCreates the shop folder.
Clone with HTTPS
git clone https://github.com/acme/shop.gitSame, over HTTPS.
Choose the folder name
git clone git@github.com:acme/shop.git my-shopClones into my-shop.
Shallow clone
git clone --depth 1 git@github.com:acme/shop.gitOnly the latest commit.
Workflow Examples
git clone git@github.com:acme/shop.gitDownload it
cd shopEnter it
git switch -c feature/searchStart your work
Troubleshooting
Permission denied (publickey)
Cause: Your SSH key is not set up on GitHub
Add your key to GitHub, or clone with the HTTPS URL
fatal: destination path 'shop' already exists
Cause: A folder with that name exists
Pick another folder name as the second argument
Repository not found
Cause: Wrong URL or no access
Check the URL and your permissions
Tips & Pitfalls
Best Practices
- ✓Use SSH URLs if you push often.
- ✓Use --depth 1 in CI pipelines.
Common Mistakes
- ✗Forgetting to cd into the new folder before running git commands.
- ✗Cloning inside another repository.
- ✗Cloning again to update — git pull does that.
FAQ
Yes, as remote-tracking branches (origin/…). Switching to one creates the local branch.
git fetch --unshallow.