← Back to Git Course | Chapter 2: Basic Commands | Lesson 4 of 18

Git clone Command

What is git clone?

git clone <url> downloads a complete copy of a remote repository -- every commit, every branch, the full history -- onto your machine in one step, giving you a fully independent local repository ready to work in immediately.

Example: What is git clone?

bash
git clone https://github.com/user/repo.git

Cloning from a Remote URL

Cloning works over HTTPS or SSH URLs, and either way Git automatically creates a remote connection named origin pointing back to that source, so future push and pull commands know exactly where to sync.

Example: Cloning from a Remote URL

bash
git clone https://github.com/user/repo.git
git remote -v

Cloning into a Specific Folder

By default the cloned folder is named after the repository itself, but git clone <url> <folder-name> lets you clone into a custom directory name -- useful when you already have a folder with that name, or want something more descriptive.

Example: Cloning into a Specific Folder

bash
git clone https://github.com/user/repo.git my-folder

Cloning a Specific Branch

Cloning normally checks out only the default branch, but git clone --branch <name> <url> lets you clone and check out a specific branch directly, skipping the extra step of switching branches after the fact.

Example: Cloning a Specific Branch

bash
git clone --branch develop https://github.com/user/repo.git

Checking the Cloned Remote

Running git remote -v right after a clone shows you the origin URL Git configured automatically -- a quick sanity check that you're pointed at the repository you actually intended to clone.

Example: Checking the Cloned Remote

bash
git remote -v

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.