Git & GitHub · Chapter 25 of 42

git clone

`git clone` downloads a complete copy of a remote repository — including all its history, branches, and files — to your local machine. It's how you get started with an existing project.

After cloning, the remote is automatically named `origin`, and you have a fully functional local repository ready for you to make commits, branches, and push changes back.

Syntax
git clone <url>
git clone <url> custom-folder-name

Cloning a repository

Run `git clone <url>` to copy a repository into a new folder named after the repository. You can also specify a custom folder name as a second argument.

What clone sets up

Clone automatically configures the `origin` remote pointing to the source URL, and checks out the default branch, usually main, ready to work with.

Example 1 (bash)
git clone https://github.com/user/repo.git
Output
Cloning into 'repo'...
remote: Enumerating objects: 120, done.
Receiving objects: 100% (120/120), done.

Downloads the full repository history into a new folder named 'repo'.

Example 2 (bash)
git clone https://github.com/user/repo.git my-copy
Output
Cloning into 'my-copy'...

Clones the repository into a folder named 'my-copy' instead of the default name.

Key points

  • git clone copies a full repository, including history, to your machine.
  • The source remote is automatically named origin.
  • You can specify a custom local folder name.
  • Cloning checks out the default branch automatically.
💡 Note: Cloning a large repository with lots of history can take time and disk space; use `--depth 1` for a shallow clone if you only need the latest snapshot.

📝 Quick Quiz

1. What does git clone do?

2. What is the default name given to the cloned remote?

3. How do you clone into a custom folder name?