~/hackweb.dev
Cloning Repositories
Quiz
...

Cloning Repositories

beginner · updated Tue Sep 08 2026Contribute

Clone an existing repo and understand HTTPS vs SSH.

Cloning Repositories

Cloning copies a remote repository to your local machine, including its full history.

Basic Clone

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

Creates a repo/ directory with all files and Git history.

What Clone Does

  • Downloads all repository data
  • Creates a working copy of the latest version
  • Sets up origin remote pointing to the source
  • Checks out the default branch (main)

HTTPS vs SSH

# HTTPS
git clone https://github.com/user/repo.git

# SSH
git clone [email protected]:user/repo.git

SSH requires key setup but avoids entering credentials each time.

Shallow Clone

git clone --depth 1 https://github.com/user/repo.git

Downloads only the latest commit — faster for large repos or CI pipelines.

Cloning into a Specific Directory

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

Best Practices

  • Use SSH for frequently accessed repos
  • Use --depth 1 for CI/CD or quick inspection
  • Clone into a meaningful directory name
  • Verify the repository before cloning (check stars, activity)

Common Mistakes

  • Cloning into a non-empty directory
  • Not having Git installed
  • Using wrong URLs (typos cause failures)
  • Confusing cloning with forking