git clone

Setup & Creating Projects

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>]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (1)

Check out this branch (or tag) instead of the remote’s default branch.

When neededStart directly on another branch

Example

git clone -b develop <url>

Intermediate (1)

Download only the given number of latest commits (a shallow clone). Implies --single-branch.

When neededFast clones for CI; history-based commands see less

Example

git clone --depth 1 <url>

Choosing the Right Option

Full vs shallow

What gets downloaded

CommandHistoryBest for
git clone <url>EverythingDaily work
git clone --depth 1 <url>Latest commit onlyCI builds, quick look

Examples

Clone with SSH

git clone git@github.com:acme/shop.git

Creates the shop folder.


Clone with HTTPS

git clone https://github.com/acme/shop.git

Same, over HTTPS.


Choose the folder name

git clone git@github.com:acme/shop.git my-shop

Clones into my-shop.


Shallow clone

git clone --depth 1 git@github.com:acme/shop.git

Only the latest commit.

Workflow Examples

1
git clone git@github.com:acme/shop.git

Download it

2
cd shop

Enter it

3
git switch -c feature/search

Start 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

A:

Yes, as remote-tracking branches (origin/…). Switching to one creates the local branch.

A:

git fetch --unshallow.