Courses / GitHub
1. Cloning a repository with git clone
How to create a local copy of a remote repository using git clone with HTTPS and SSH URLs.
How It Works
Think of the remote repo as a library archive and git clone as downloading a full snapshot plus its entire history into a new folder on your computer so you can browse and make changes locally.
You run git clone <URL> and Git creates a new directory named after the repo.
Git fetches all commits, branches, and tags from the remote and writes them into the .git folder.
Git checks out the default branch (usually main or master) into the working directory.
See It
The first two commands create local copies of the git/git repository using two authentication methods: HTTPS prompts for credentials or token, SSH uses your SSH key. The ls and git rev-parse commands confirm the folder exists and show the checked-out branch. Try cloning a small public repo instead (e.g., octocat/Hello-World) to see faster results.
# Clone over HTTPS
git clone https://github.com/git/git.git
# Clone over SSH (requires your SSH key added to GitHub)
git clone git@github.com:git/git.git
# Show repository folder and current branch
ls -d git
cd git && git rev-parse --abbrev-ref HEADUse It
Cloning a teammate's project to run it and submit a pull request.
# Clone teammate's repo (HTTPS)
git clone https://github.com/your-teammate/project.git
cd project
# Create a new feature branch for your work
git switch -c feature/fix-bugCloning gives you the full history and a writable working tree so you can test, modify, and commit changes that can be pushed back as a PR.
Break It
What will happen when you run these commands?
# Attempt to clone using an HTTP URL that requires authentication, expecting SSH key to be used automatically
git clone http://github.com/your-teammate/project.git
# then try to push without configuring credentials
cd project
touch fix.txt && git add fix.txt && git commit -m "fix" && git push origin mainHTTP(S) and SSH are distinct transports: cloning via http(s) does not make Git use your SSH key for network operations; if the repo is private you'll be asked for HTTP credentials (username/password or token) when cloning, and pushing over HTTP also requires credentials — so the later git push will be rejected unless you supply proper HTTP credentials or switch the remote to an SSH URL. The surprising bit is assuming SSH keys magically apply when you used an HTTP URL.
Clone using the SSH URL (or configure HTTP credentials) so the remote uses the transport that matches your authentication method.
# Correct: clone using SSH so your SSH key is used for push/pull
git clone git@github.com:your-teammate/project.git
cd project
touch fix.txt && git add fix.txt && git commit -m "fix" && git push origin mainLevel Up
Shallow clone (--depth): Use --depth=1 to clone only the latest snapshot (faster and smaller) when full history isn't needed.
Sparse checkout: Configure sparse-checkout to clone the whole repo but check out only specific folders into your working tree to save space.
Mirror clone (git clone --mirror): Create a complete mirror suitable for backups or a new remote, copying all refs exactly.
Prove It
Clone a public repository, create a new branch named feature/test-clone, create an empty file named proof.txt, commit it, and push the branch to the origin.
Git / Bash
Cloning a repository with git clone
Make a local copy of a remote Git repository so you can inspect, edit, and version-track files on your machine.
"I want the exact project on my laptop so I can run and change it locally."
git clone copies a remote repository (history and files) to a new local directory; you can clone using HTTPS or SSH URLs depending on how you authenticate.
"I want the exact project on my laptop so I can run and change it locally."
git clone copies a remote repository (history and files) to a new local directory; you can clone using HTTPS or SSH URLs depending on how you authenticate.