CurriculumRemote Repositoriesgit clone — Copying a Repository
Lesson 2 of 729%
Intermediate6 min+60 XP

git clone — Copying a Repository

git clone downloads a complete copy of a remote repository — all files, all branches, all commits, and full history. It also automatically configures the "origin" remote pointing back to the source.

01.What Clone Does in One Command

Running git clone: downloads the entire repository, creates a local folder with the repo name, initializes git inside it, sets up origin pointing to the source URL, checks out the default branch (usually main), creates remote-tracking branches for all remote branches. You go from zero to fully set up in seconds.

Distributed Architecture
💻
Your Local
push / pull
☁️
GitHub (Remote)
push / pull
💻
Teammate's Local

02.Cloning Options

Clone into a custom folder name by passing it as a second argument. Use --branch to check out a specific branch immediately. Use --depth 1 for a "shallow clone" that only downloads the latest snapshot — dramatically faster for large repositories when you don't need full history. Use SSH URLs for passwordless authentication.

my-project/
📁my-project/
📁.git/← Git database
📄config
📄HEAD
📁objects/
📁refs/
📄README.md
📁src/

Commands

commands — click to reveal output
$
git clone https://github.com/user/repo.git
Clone into a folder named "repo"
▼ show output
$
git clone https://github.com/user/repo.git my-app
Clone into a custom folder name
$
git clone --branch develop https://github.com/user/repo.git
Clone and immediately check out a specific branch
$
git clone --depth 1 https://github.com/user/large-repo.git
Shallow clone — latest snapshot only (much faster for big repos)
$
git clone git@github.com:user/repo.git
Clone via SSH (no password prompts needed)
KNOWLEDGE CHECK

What does git clone automatically set up?

Rate this lesson:
PreviousNext Lesson