How to

How to Clone a Repository from GitHub: A Step-by-Step Guide

Sanket Shah

By Sanket Shah

Jan 13, 2026

Updated Jun 24, 2026

How to Clone a Repository from GitHub: A Step-by-Step Guide

Clone a GitHub repo with git clone [url] in your terminal. Find the URL under the green Code button. Use HTTPS for beginners, SSH for daily contributors. Verify with cd repo-name and git remote -v. Advanced options include shallow clones, branch-specific clones, and submodule support.

Cloning a repository copies an entire GitHub project, code, branches, and history, onto your computer so you can work on it locally. With over 180 million developers building on GitHub, knowing how to clone a repository from GitHub correctly is a basic but essential skill.

This guide walks through the exact steps, from finding the repo URL to verifying your local copy, plus advanced techniques, real-world use cases, and troubleshooting for every scenario you will encounter.

Four-step visual guide to cloning a GitHub repository.png

Four-step visual guide to cloning a GitHub repository

The four core steps to clone a repository from GitHub: find the URL, open your terminal, run git clone, and verify your files.

What Is a Git Repository and Why Does Cloning Matter?

A git repository is a smart project folder that stores every file, tracks every change, and preserves the full history of your project. Every commit, branch, and tag is recorded so you can roll back mistakes, compare versions, and collaborate without overwriting each other's work.

Cloning creates a complete, independent local copy of that repository on your machine. Unlike simply downloading a ZIP file, a clone preserves the full commit history and all branches, maintains a live connection to the remote repository (called origin), and lets you push changes back, pull updates, and open pull requests. It also works offline once the initial clone is complete.

This is why cloning is the standard first step for any developer joining a project, contributing to open source, or setting up a new development environment.

Git Clone vs. Git Fork vs. Git Download

Understanding this distinction prevents a very common beginner mistake: downloading a ZIP and wondering why Git commands do not work.

ActionPreserves HistoryRemote ConnectionCan Push BackUse Case
git cloneYesYes (origin)Yes (with permission)Local development
Fork (GitHub UI)YesYes (upstream)Via pull requestOpen source contribution
Download ZIPNoNoNoQuick file inspection only
git initNo (starts fresh)NoAfter adding remoteBrand-new project

Prerequisites Before You Clone a Repository from GitHub

Before jumping into cloning a repository, it is good to get a few things in order. Think of this as your warm-up to ensure everything goes smoothly.

  • Git installed on your local computer. This is the tool that tracks changes and lets you clone repositories. Verify with git --version in your terminal.
  • A GitHub account. You need this to access remote repositories and manage your projects, especially private ones.
  • Git Bash or terminal access. This is where you will run the git commands. On Windows, use Git Bash or PowerShell; on macOS/Linux, use the built-in Terminal.
  • A local directory where the repository will live. This is the folder on your computer where the project files will be stored.
  • SSH key configured (optional but recommended). If you plan to clone private repositories or push changes frequently, setting up an SSH key eliminates the need to enter credentials on every operation.

These prerequisites make cloning smoother and help prevent common errors. Having them ready will save you time and frustration later.

Checking Your Git Version

1git --version 2# Expected output: git version 2.x.x

If Git is not installed, download it from git-scm.com and follow the installer for your operating system.

Understanding Repository URLs and Access

Every GitHub repository has a unique URL that points to its location on the server. You can choose between HTTPS and SSH links, and the right choice depends on your workflow.

HTTPS vs SSH comparison card for GitHub cloning.png

HTTPS vs SSH comparison card for GitHub cloning

HTTPS works immediately for beginners; SSH is the preferred choice for developers who push and pull code daily.

HTTPS vs. SSH: Which Should You Use?

FeatureHTTPSSSH
Setup requiredNone (works immediately)SSH key pair must be generated and added to GitHub
AuthenticationUsername + Personal Access TokenKey pair (no password each time)
Firewall compatibilityWorks behind most firewallsMay be blocked on port 22 in some corporate networks
Best forBeginners, public repos, one-time clonesFrequent contributors, CI/CD pipelines, private repos
SecuritySecure (TLS encrypted)Highly secure (asymmetric key encryption)

HTTPS URL format:

https://github.com/username/repository-name.git

SSH URL format:

git@github.com:username/repository-name.git

GitHub CLI format (if you have gh installed):

gh repo clone username/repository-name

Step-by-Step: How to Clone a Repository from GitHub

Step 1: Find the Repository URL

Navigate to the GitHub repository you want to clone. Click the green Code button near the top of the page. This opens a dropdown with options for HTTPS, SSH, and GitHub CLI. Click the copy icon next to the URL you want.

Use HTTPS if you are cloning a public repo or have not set up SSH keys yet. Use SSH if you have already added an SSH key to your GitHub account; it saves you from entering credentials every time.

Step 2: Open Your Terminal or Git Bash

Open Git Bash on Windows or Terminal on macOS/Linux. Navigate to the location where you want the project stored. If you would like to create a new folder for it first:

1mkdir my-projects 2cd my-projects

Pro tip: Keep all your repositories in a single parent directory (e.g., ~/projects or C:\dev) so they are easy to find and manage.

Step 3: Run the Git Clone Command

Run the git clone command followed by the URL you copied in Step 1:

1git clone https://github.com/username/repository-name.git

Press Enter. Git will start downloading the repository, showing progress messages such as:

Cloning into 'repository-name'... remote: Enumerating objects: 1234, done. remote: Counting objects: 100% (1234/1234), done. Receiving objects: 100% (1234/1234), 5.23 MiB | 8.10 MiB/s, done. Resolving deltas: 100% (789/789), done.

These messages indicate Git is transferring the repository's files and history to your machine.

Step 4: Verify the Cloned Repository

Once cloning finishes, a new folder named after the repository will appear in your current directory. Move into it:

1cd repository-name 2git remote -v # Confirms the remote URL is correctly set 3git log --oneline -5 # Shows the last 5 commits

You should see the project's files and folders, confirming you now have a full local copy of the repository, including its commit history.

Step 5: Start Working with the Cloned Repository

Never commit directly to main — always create a feature branch after cloning. The standard Git workflow from here is:

1git checkout -b feature/my-new-feature 2git add . 3git commit -m "feat: add user authentication module" 4git push origin feature/my-new-feature

From here, your local copy stays in sync with the remote repository through Git's standard workflow of pulling, committing, and pushing changes.

How the Git Clone Workflow Works

Figure: Simplified git clone decision flow from GitHub to your local machine.

Advanced Git Clone Techniques

Once you are comfortable with the basic clone, these advanced options will save significant time and disk space on larger projects.

Shallow Clone: Get Only the Latest Code

For large repositories where you do not need the full history (e.g., deploying code or quick exploration):

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

This downloads only the most recent commit, dramatically reducing clone time and storage. The Linux kernel repository is over 4 GB with full history, but under 200 MB with --depth 1.

Clone a Specific Branch

When you only need a particular branch, not the entire repository:

1git clone -b develop https://github.com/username/repo.git

Clone with Submodules

Many projects include submodules (nested repositories). Without the flag, submodules appear as empty folders:

1git clone --recurse-submodules https://github.com/username/repo.git

If you already cloned without this flag, fix it with:

1git submodule update --init --recursive

Sparse Checkout: Clone Only Specific Folders

For monorepos where you only need one subdirectory:

1git clone --filter=blob:none --sparse https://github.com/username/monorepo.git 2cd monorepo 3git sparse-checkout set path/to/subfolder

Complete Git Clone Command Reference

Before running these commands, make sure you are in the correct directory on your local machine and have the necessary permissions to access the remote repository.

CommandDescriptionWhen to Use
git clone [url]Clone the entire repository with full historyStandard development setup
git clone -b [branch] [url]Clone a specific branch onlyWorking on a non-default branch
git clone --depth 1 [url]Shallow clone, latest commit onlyCI/CD, deployment, quick exploration
git clone --recurse-submodules [url]Clone with all submodulesProjects with nested dependencies
git clone [url] .Clone into the current directory (must be empty)Pre-created target directory
git clone --mirror [url]Full mirror backup including all refsRepository backup and migration
git clone --sparse [url]Sparse checkout for large monoreposMonorepo with many packages
git initInitialize an empty git repositoryStarting a brand-new project
git fetchFetch updates from remote without mergingChecking for remote changes
git remote -vView configured remote URLsVerifying clone origin

GitHub and Git: Key Statistics

GitHub hosts over 330 million repositories, making it the world's largest code hosting platform. A new developer joins GitHub every second, and the platform processes millions of git clone operations daily.

Data-driven GitHub statistics infographic.png

Data-driven GitHub statistics infographic

Key GitHub statistics that highlight why efficient cloning techniques like shallow clone matter for modern developers.

The average open-source repository has grown significantly in size over the past decade, driven by larger asset files, more comprehensive test suites, and longer commit histories. Using --depth 1 for read-only workflows like deployments and CI pipelines is now considered a best practice in professional engineering teams.

Real-World Use Cases for Git Clone

Understanding when and why developers clone repositories helps you apply the skill confidently in different contexts.

Use Case 1: Joining an Existing Team Project

When you join a company or open-source project, the first thing you do is clone the main repository. This gives you an identical copy of what every other developer is working with, ensuring consistency across the team. Consistent local environments are the foundation of reliable collaborative development, and git clone is what makes that possible.

1git clone git@github.com:company/product.git 2cd product 3npm install

Use Case 2: Contributing to Open Source

Contributing to open source typically involves forking first (via GitHub UI), then cloning your fork. Adding upstream lets you pull in the original project's updates while keeping your fork in sync.

1git clone https://github.com/YOUR-USERNAME/open-source-project.git 2cd open-source-project 3git remote add upstream https://github.com/ORIGINAL-OWNER/open-source-project.git

Use Case 3: Deploying Code to a Server

On a production or staging server, you clone the repository to deploy your application. For automated deployments, --depth 1 is common to keep the server's disk usage minimal.

1git clone https://github.com/company/app.git /var/www/app 2cd /var/www/app 3git checkout main

Use Case 4: Learning from Existing Codebases

Cloning popular repositories is one of the fastest ways to learn professional coding patterns. Studying how large, well-maintained projects structure their code accelerates your growth far faster than tutorials alone. This pairs naturally with using AI coding assistant tools to understand and extend what you find.

Use Case 5: Setting Up a Local Development Environment

When switching computers or onboarding a new machine, cloning restores your entire project instantly. No manual file transfers, no missing files, no version mismatches.

Troubleshooting Common Git Clone Errors

A few issues come up often enough that it is worth checking for them before, or right after, running git clone.

Common Git clone errors and their fixes.png

Common Git clone errors and their fixes

The four most common git clone errors and their exact fixes, ready to reference when something goes wrong.

Error: "Repository Not Found" or 404

Cause: The URL is wrong, the repository is private, or you do not have access.

1git clone https://YOUR-TOKEN@github.com/username/private-repo.git

Error: "Authentication Failed" on HTTPS

Cause: GitHub no longer accepts account passwords for HTTPS clones. If prompted for a password and it fails, generate a Personal Access Token (Settings → Developer settings → Personal access tokens) and use that instead.

1git clone https://github.com/username/repo.git 2# Username: your-github-username 3# Password: ghp_xxxxxxxxxxxxxxxxxxxx (your PAT)

Error: "Permission Denied (publickey)" on SSH

Cause: Your SSH key is not added to GitHub or the SSH agent is not running.

1ssh-add -l # Check if your SSH key is loaded 2ssh-add ~/.ssh/id_ed25519 # Add it if not loaded 3ssh -T git@github.com # Test the connection

Error: "Destination Path Already Exists"

Cause: A folder with the same name as the repository already exists in your current directory.

1git clone https://github.com/username/repo.git repo-v2

Slow Clone Speed

Cause: Large repository with extensive history.

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

Cloning Private Repositories: A Complete Guide

Private repositories require authentication. Here are all the methods, from simplest to most secure.

Method 1: Personal Access Token (HTTPS)

Generate a PAT at GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic). Grant repo scope. To avoid re-entering credentials, store them:

1git config --global credential.helper store

Method 2: SSH Key Authentication

1ssh-keygen -t ed25519 -C "your-email@example.com" 2cat ~/.ssh/id_ed25519.pub 3# Add to GitHub: Settings → SSH and GPG keys → New SSH key 4git clone git@github.com:username/private-repo.git

Method 3: GitHub CLI

1gh auth login 2gh repo clone username/private-repo

Method 4: Deploy Keys (for Servers)

For CI/CD pipelines and servers, use repository-specific deploy keys with read-only access. This is the most secure option for automated environments because each key is scoped to a single repository and can be revoked independently.

Git Clone Best Practices

Following these practices will save you from common mistakes and keep your repositories organized.

1. Always clone into a dedicated directory structure. Keep work, personal, and open-source projects in separate parent folders for clarity.

2. Verify the remote after cloning with git remote -v to confirm the origin URL is correct before making any changes.

3. Never commit directly to main. Always create a feature branch immediately after cloning. This is a non-negotiable habit in professional teams and is central to understanding vibe coding vs traditional coding workflows.

4. Use SSH for repositories you contribute to regularly. SSH eliminates credential prompts and is more secure for long-term projects.

5. Keep your clone up to date before starting any new work:

1git pull origin main

6. Use .gitignore before your first commit to ensure sensitive files like .env are never accidentally pushed.

Rocket.new: From Cloned Repository to Deployed App

Rocket.new is a vibe solutioning platform that combines AI app building, strategic research, and competitive intelligence in one product. When it comes to GitHub workflows, Rocket.new supports importing existing Next.js TypeScript repositories directly, so you can pick up where you left off and build on top of your existing code with AI.

image - 2026-06-12T173607.284.png Rocket.new enables two-way GitHub sync, AI-powered iteration, and direct repository import for Next.js TypeScript projects.

Once you import a repository into Rocket.new, you get full two-way sync with GitHub. Rocket pushes changes to a rocket-update branch and automatically opens a pull request to main for each batch of AI-generated or manual edits. You can also pull in the latest state of main from your local IDE or teammates without leaving Rocket.

Starting MethodBest For
From GitHubYou already have a Next.js TypeScript codebase and want to enhance it with AI
From an ideaStarting fresh with a plain-language description
From a templateLaunching quickly from a pre-built starting point
RedesignRebuilding or redesigning an existing website

If you are interested in how full-stack code automation fits into modern development, Rocket.new's Build pillar is designed exactly for that. Developers who want to go further can also explore web development tools that complement a Git-based workflow.

For teams thinking about the bigger picture, learning how to build a startup with vibe coding shows how AI-assisted development and version control work together from idea to launch. No complicated setup. No endless configuration. Just your project, ready to go.

How to Clone a Repository from GitHub: Summary

Cloning a repository is a simple but powerful way to get a full working copy of a project on your local machine. Knowing how to clone a repository from GitHub helps you collaborate, learn, and experiment at the speed of professional developers. Git makes version control painless once you get the hang of commands like git clone, git fetch, and git init.

Having a local copy of a repository means you can work offline, test new ideas safely, and track all changes before pushing them back to GitHub. It is like having a personal playground for your code, with full access to the project's history and branches. For a related skill, see our guide on how to delete a repository in GitHub once you no longer need a local or remote copy.

Start building with Rocket for free and experience the fastest path from cloned repository to deployed, production-ready app.

Table of contents

About Author

Photo of Sanket Shah

Sanket Shah

Software Development Executive - II

He crafts innovative solutions that streamline workflows and empower developers to bring their ideas to life. His passion lies in transforming complex challenges into elegant, user-friendly experiences.

Decorative background for the call-to-action section

The work is only as good as the thinking before it.

You already know what you're trying to figure out. Type it. Rocket handles everything after that.