Cloning a Repository

git clone copies a complete remote repository, including its full history, to your machine.

Syntaxgit clone <url> [folder]

git clone downloads an entire repository — all files, branches, and history — and automatically sets up origin for you. It is the usual way to start working on an existing project.

Clone options

  • git clone <url> — clone into a folder named after the repo.
  • git clone <url> my-folder — clone into a folder you name.

After cloning you can immediately branch, commit, and push (if you have write access).

Example

Example · bash
# Clone over HTTPS
git clone https://github.com/octocat/Hello-World.git

# Clone over SSH into a custom folder
git clone [email protected]:octocat/Hello-World.git hello

When to use it

  • A new team member clones the company repo on their first day to get a full local copy of the project.
  • A contributor clones an open-source repo to explore the codebase and prepare a bug-fix pull request.
  • A developer clones a specific tag of a repo to reproduce an exact historical release for a support investigation.

More examples

Clone a public repository

Downloads the full repository history and working tree into a new local folder named after the repo.

Example · bash
git clone https://github.com/expressjs/express.git
cd express
git log --oneline -5

Clone into a custom folder name

Appending a directory name tells Git to place the clone in that folder instead of using the repo name.

Example · bash
git clone https://github.com/username/my-project.git work-app
cd work-app

Shallow clone for faster download

A shallow clone downloads only recent history, cutting clone time and disk usage dramatically for large repos.

Example · bash
# Only fetch the last 10 commits
git clone --depth 10 https://github.com/torvalds/linux.git
du -sh linux/
# Significantly smaller than a full clone

Discussion

  • Be the first to comment on this lesson.
Cloning a Repository — GitHub | SoundsCode