Home Coding & Scripting Cloning a GitHub Repository into Our Local Machine

Cloning a GitHub Repository into Our Local Machine

285
0

Whenever we want to work on a project from GitHub, the first step is to clone it — download a complete copy of the repository into our computer. Once we clone a repo, we can freely edit files, run the project locally, create commits, and push changes back to GitHub.

In this guide, we’ll walk through how to clone a repository the right way, using the latest GitHub interface and three available cloning options: HTTPS, SSH, and GitHub CLI.


1. What Does “Cloning” Mean?

When we clone a repository, Git:

  • Downloads all files
  • Copies the complete commit history
  • Connects our local machine to the remote repo
  • Lets us start working locally right away

After cloning, our computer has a fully functional Git project.


2. Where We Find the Clone Options on GitHub

On any GitHub repository page, we click the green <> Code button.

We’ll see two tabs:

A. Local

This is where GitHub gives us three cloning options:

  1. HTTPS
  2. SSH
  3. GitHub CLI

B. Codespaces

This opens GitHub’s cloud-based development environment.
(Not for local cloning.)

For working locally, we always stay on the Local tab.


3. Cloning Using HTTPS (Our Easiest Starting Point)

HTTPS is the simplest and most beginner-friendly method.
We can start using Git immediately without setting up keys.

Steps

  1. Click Code → Local → HTTPS
  2. Copy the HTTPS link: https://github.com/username/repository.git
  3. Run this command in our terminal: git clone https://github.com/username/repository.git
  4. Go into the project folder: cd repository

When we should use HTTPS

  • We are beginners
  • We are behind a firewall or school/office network
  • We want the simplest setup

When we push changes, Git may ask us for a Personal Access Token instead of a password.
That’s normal now.


4. Cloning Using SSH (Great for Frequent Contributors Like Us)

SSH uses key-based authentication. Once we set it up, Git will stop asking for credentials again and again.

Steps

  1. Click Code → Local → SSH
  2. Copy the SSH link: git@github.com:username/repository.git
  3. Clone the repo: git clone git@github.com:username/repository.git
  4. Move into the folder: cd repository

When we should use SSH

  • We push and pull often
  • We want a secure, password-free workflow
  • We work on multiple repositories
  • We use automation or CI/CD

SSH is perfect for those of us who code regularly.


5. Cloning Using GitHub CLI (Perfect if We Love Terminal Work)

GitHub CLI (gh) is a powerful tool if we prefer command-line workflows.

Steps

  1. Install GitHub CLI
  2. Log in: gh auth login
  3. Clone the repo: gh repo clone username/repository

When we should use GitHub CLI

  • We enjoy working fully in the terminal
  • We want fast authentication
  • We use GitHub features like issues and PRs from the CLI

For advanced students, this becomes the easiest method.


6. Which Cloning Method Should We Choose?

Here’s a simple guide:

Our SituationBest Method
We are beginnersHTTPS
We are behind a firewall or proxyHTTPS
We push and pull dailySSH
We use scripts or automationSSH
We prefer command-line toolsGitHub CLI

All three methods are secure. We simply pick what suits our workflow or just what we are more comfortable with.


7. Optional: Faster Cloning With Shallow Copy

If we don’t need the full history:

git clone --depth 1 <url>

This saves time and disk space.


8. Optional: Cloning Only Part of a Repository

For huge repositories, we can clone only the folder we need:

git clone --filter=blob:none <url>
cd repo
git sparse-checkout init --cone
git sparse-checkout set folder-name

9. Summary

  • We click Code → Local to find the cloning options
  • GitHub offers HTTPS, SSH, and GitHub CLI
  • HTTPS → simplest
  • SSH → best for frequent contributors
  • CLI → best for power users
  • We can switch methods later if needed

Cloning is the first step in becoming confident with Git and GitHub.
Once we know how to clone a repo, we can start building, experimenting, and contributing with ease.


References

  • GitHub Docs — “Cloning a repository”
  • GitHub Docs — “Which remote URL should I use?”
  • GitHub Docs — “Connecting to GitHub with SSH”
  • GitHub CLI Documentation
Previous articleUsing Git Tags to Mark Important Moments in Our Project
Next articleForking a GitHub Repository and When We Should Use It
Heartin Kanikathottu
As a seasoned Cloud and Security Architect, I’ve led transformative initiatives in key roles, including Vice President at Morgan Stanley, Principal Architect at Societe Generale, and Tech Lead & Cloud Security Architect at VMware, among others. I’m also an internationally published author with multiple books available on platforms like Amazon and O'Reilly. Notably, one of my books was recognized as the 8th best cloud computing book of all time in 2020, reflecting the impact of my contributions to the field. With over 15 professional certifications from providers such as Microsoft (Azure), Amazon (AWS), Oracle (Java), Pivotal (Spring), and IBM, I bring a wealth of expertise to my work. Academically, I hold dual Master’s degrees in Cloud Computing and Data Analytics. I’m passionate about sharing knowledge and mentoring others, which is why I actively speak at global technical forums such as Tech Opportunities Fest at Platform Calgary, Google's Kubernetes Meetup, Java User Group, Elasticsearch Meetup, and the Agile India Conference.

LEAVE A REPLY

Please enter your comment!
Please enter your name here