Falytom logoFALYTOM
Games
ToolsUI ComponentsServicesProductsAbout
menu
  1. Home
  2. /Web Development
  3. /Github
  4. /Cloning Repositories
Your Progress0%
0 of 20 completed

Git & Github Topics

Getting Started

  • What is Git?
  • What is GitHub?
  • Installing & Configuring Git
  • Your First Git Repository

Core Git Concepts

  • Understanding Commits & History
  • Working with Branches
  • Merging Branches
  • The Staging Area
  • Undoing Changes

Working with GitHub

  • Connecting to GitHub
  • Pushing & Pulling Code
  • Cloning Repositories
  • GitHub README & Documentation

Collaboration Workflows

  • Forking & Pull Requests
  • Code Review Basics
  • Handling Merge Conflicts
  • Issues & Project Management

Best Practices & Workflows

  • Git Workflow Best Practices
  • Working with .gitignore
  • Common Git Problems & Solutions

Cloning Repositories

Download and work with existing Git repositories

Cloning is how you download existing repositories from GitHub to your local machine. Whether you're joining a team project, contributing to open source, or learning from others' code, cloning is your starting point. In this lesson, you'll learn how to clone repositories, understand what happens during a clone, work with cloned projects, and know when to fork vs clone. By the end, you'll be able to work with any repository on GitHub.

What Is Cloning?

Cloning creates a complete local copy of a remote repository. When you clone, you get:

  • All files in the repository
  • Complete commit history
  • All branches
  • All tags
  • Automatic remote connection (called "origin")

Think of it like:

Downloading a ZIP file gives you the current files. Cloning gives you the entire project history and the ability to contribute back!

When to Clone

  • Joining a team project: Get the project to work on
  • Contributing to open source: Download to make changes
  • Learning from code: Study how others build things
  • Using a template: Start with an existing project structure
  • Working on multiple computers: Get your own projects on different machines

How to Clone a Repository

Step 1: Find the Repository URL

On GitHub, navigate to the repository you want to clone:

  1. Go to the repository page on GitHub
  2. Click the green "Code" button
  3. You'll see URL options:
    • HTTPS: https://github.com/username/repo.git
    • SSH: git@github.com:username/repo.git
    • GitHub CLI: gh repo clone command
  4. Copy the URL (HTTPS is easiest for beginners; SSH if you've set it up)

Step 2: Clone the Repository

In your terminal, navigate to where you want the project:

BASH
# Navigate to your projects folder
cd ~/Documents/projects

# Clone with HTTPS
git clone https://github.com/username/repository.git

# Or clone with SSH
git clone git@github.com:username/repository.git

What Happens During Clone

You'll see output like:

TEXT
Cloning into 'repository'...
remote: Enumerating objects: 125, done.
remote: Counting objects: 100% (125/125), done.
remote: Compressing objects: 100% (85/85), done.
remote: Total 125 (delta 45), reused 98 (delta 32), pack-reused 0
Receiving objects: 100% (125/125), 1.23 MiB | 2.45 MiB/s, done.
Resolving deltas: 100% (45/45), done.

Git:

  1. Creates a new folder with the repository name
  2. Downloads all objects (commits, files, history)
  3. Sets up the remote connection (origin)
  4. Checks out the default branch (usually main or master)

Step 3: Navigate into the Repository

BASH
cd repository

# You're now in the cloned repository!
ls -la  # See all files including .git

Success! You now have a complete working copy of the repository with full Git history.

Clone Options and Variations

Clone into a Different Directory Name

BASH
# Clone into a folder with a different name
git clone https://github.com/user/repo.git my-project-name

# Creates folder 'my-project-name' instead of 'repo'

Clone a Specific Branch

BASH
# Clone only a specific branch
git clone -b branch-name https://github.com/user/repo.git

# Example: clone the 'develop' branch
git clone -b develop https://github.com/user/repo.git

Shallow Clone (Faster, Less History)

BASH
# Clone with limited history (faster for large projects)
git clone --depth 1 https://github.com/user/repo.git

# Only gets the latest commit, not entire history
# Good for: quick testing, CI/CD, large repositories

Shallow clone limitations:

  • Can't see full history
  • Some Git operations won't work properly
  • Use only when you don't need history

Clone Without Checking Out Files

BASH
# Clone repository structure without working files
git clone --bare https://github.com/user/repo.git

# Creates a .git folder with no working directory
# Useful for: server-side repositories, mirrors

Clone a Subdirectory (Sparse Checkout)

BASH
# Clone only specific folders (Git 2.25+)
git clone --filter=blob:none --sparse https://github.com/user/repo.git
cd repo
git sparse-checkout set path/to/folder

# Only downloads the specified folder

What to Do After Cloning

1. Verify the Clone

BASH
# Check remote is set up
git remote -v

# Output:
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)

# Check current branch
git branch

# Check commit history
git log --oneline -5

2. Explore the Repository

BASH
# See all branches (local and remote)
git branch -a

# Check repository status
git status

# View available tags
git tag

# Read documentation
cat README.md

3. Install Dependencies (If Applicable)

Most projects require installing dependencies:

BASH
# For Node.js projects
npm install
# or
yarn install

# For Python projects
pip install -r requirements.txt

# For Ruby projects
bundle install

# Check the README for specific instructions!

4. Create Your Own Branch for Changes

BASH
# Don't work directly on main
git switch -c feature/my-changes

# Now you can make changes safely

Fork vs Clone: Understanding the Difference

What Is Forking?

Forking creates a copy of someone else's repository in your GitHub account. It's a GitHub feature, not a Git command.

What Is Cloning?

Cloning downloads a repository to your local computer. It's a Git command.

Key Differences

Fork (GitHub):

  • Creates a copy on GitHub (in your account)
  • Maintains connection to original repository
  • Lets you propose changes via Pull Requests
  • Done through GitHub website

Clone (Git):

  • Creates a copy on your computer
  • Connects to the repository you cloned from
  • Lets you work locally
  • Done through Git command line

Typical Workflow

TEXT
Original Repo → Fork (your copy on GitHub) → Clone (your copy locally)
  (GitHub)         (GitHub)                       (Your computer)
  
You can't push to → You can push to → You work here
the original         your fork           and commit

When to Fork vs Clone Directly

Fork first, then clone when:

  • Contributing to open source
  • You don't have write access to the original repository
  • You want to experiment without affecting the original
  • You plan to suggest changes back (via Pull Request)

Clone directly (no fork needed) when:

  • It's your own repository
  • You're a collaborator with write access
  • You just want to study the code (read-only)
  • It's a team project where you have permission

The Fork-and-Clone Workflow

Here's the complete workflow for contributing to someone else's project:

Step 1: Fork on GitHub

  1. Go to the repository you want to contribute to
  2. Click the "Fork" button (top-right)
  3. GitHub creates a copy in your account
  4. You now have: https://github.com/YOU/repo (forked from https://github.com/ORIGINAL/repo)

Step 2: Clone Your Fork

BASH
# Clone YOUR fork (not the original)
git clone https://github.com/YOUR-USERNAME/repo.git
cd repo

Step 3: Add Upstream Remote

Add the original repository as "upstream" so you can get updates:

BASH
# Add the original repo as 'upstream'
git remote add upstream https://github.com/ORIGINAL-OWNER/repo.git

# Verify remotes
git remote -v

# You should see:
# origin    https://github.com/YOUR-USERNAME/repo.git (fetch)
# origin    https://github.com/YOUR-USERNAME/repo.git (push)
# upstream  https://github.com/ORIGINAL-OWNER/repo.git (fetch)
# upstream  https://github.com/ORIGINAL-OWNER/repo.git (push)

Step 4: Keep Your Fork Updated

BASH
# Fetch changes from the original repository
git fetch upstream

# Merge them into your local main branch
git switch main
git merge upstream/main

# Push to your fork
git push origin main

Step 5: Make Your Changes

BASH
# Create a feature branch
git switch -c feature/my-contribution

# Make changes, commit
git add .
git commit -m "Add my awesome feature"

# Push to YOUR fork
git push origin feature/my-contribution

Step 6: Create a Pull Request

  1. Go to your fork on GitHub
  2. Click "Compare & pull request"
  3. Write a description of your changes
  4. Submit the pull request to the original repository

🎯 The Complete Fork Workflow

This workflow lets you contribute to any public repository on GitHub! You work in your fork, and when ready, propose your changes to be merged into the original via a Pull Request.

Cloning Your Own Repositories

You'll often clone your own repositories to work on different computers:

Scenario: Working from Multiple Computers

BASH
# On your work computer
git clone https://github.com/YOUR-USERNAME/your-project.git
# Work and push changes
git push

# Later, on your laptop
git clone https://github.com/YOUR-USERNAME/your-project.git
# Your work computer's changes are there!

# Make more changes on laptop
git push

# Back on work computer
git pull  # Gets laptop changes

Multiple Clones = Same Repository

You can have multiple clones of the same repository. They're all independent copies that sync through the remote:

TEXT
Computer A Clone ←→ GitHub Repository ←→ Computer B Clone
                    ↓                          ↓
              (git push/pull)            (git push/pull)
              
All clones stay in sync through push and pull!

Best Practices for Cloning

1. Organize Your Repositories

BASH
# Create a dedicated projects folder
mkdir -p ~/Documents/projects
cd ~/Documents/projects

# Clone repositories here
git clone https://github.com/user/repo.git

# Result:
# ~/Documents/projects/
#   ├── repo1/
#   ├── repo2/
#   └── repo3/

2. Read the README First

After cloning, always read the README:

  • Setup instructions
  • Dependencies to install
  • How to run the project
  • Contribution guidelines

3. Use SSH for Repositories You Contribute To

BASH
# If you'll be pushing often, use SSH
git clone git@github.com:username/repo.git

# More convenient than HTTPS for frequent pushes

4. Don't Modify Main Directly

BASH
# After cloning, create a branch for your work
git switch -c feature/my-changes

# Keep main clean and in sync with upstream

5. Keep Your Fork Updated

If you forked a repository, regularly sync with the original:

BASH
# Add upstream if not already added
git remote add upstream https://github.com/original/repo.git

# Regular sync
git fetch upstream
git switch main
git merge upstream/main
git push origin main

Practice Clone Commands

Try these commands to practice cloning and exploring repositories:

Practice Git Clone

Explore cloned repository structure

$

Try these examples:

Troubleshooting Clone Issues

Issue: Permission Denied

Error: "Permission denied (publickey)" or "Authentication failed"

Solutions:

  • For SSH: Make sure your SSH key is set up and added to GitHub
  • For HTTPS: Ensure you're using a Personal Access Token, not password
  • Check if repository is private and you have access
  • Try HTTPS instead of SSH if SSH continues to fail

Issue: Repository Not Found

Error: "Repository not found" or "404 Not Found"

Solutions:

  • Double-check the URL for typos
  • Verify the repository exists on GitHub
  • Check if it's a private repo you don't have access to
  • Ensure the username/organization name is correct

Issue: Clone is Very Slow

Problem: Large repository taking forever to clone

Solutions:

BASH
# Use shallow clone
git clone --depth 1 https://github.com/user/large-repo.git

# Clone specific branch only
git clone -b main --single-branch https://github.com/user/repo.git

Issue: Out of Disk Space

Error: Clone fails due to disk space

Solutions:

  • Free up disk space
  • Clone to a different location with more space
  • Use shallow clone to reduce size

Command Reference

Here's a quick reference of clone commands:

BASH
# Basic Cloning
git clone <url>                        # Clone repository
git clone <url> <directory>            # Clone into specific folder
git clone -b <branch> <url>            # Clone specific branch

# Clone Options
git clone --depth 1 <url>              # Shallow clone (latest commit only)
git clone --single-branch <url>        # Clone only default branch
git clone --bare <url>                 # Clone without working directory
git clone --mirror <url>               # Clone mirror (for backups)

# After Cloning
git remote -v                          # View configured remotes
git remote add upstream <url>          # Add original repo as upstream
git fetch upstream                     # Get updates from upstream
git branch -a                          # See all branches
git log --oneline -10                  # View recent commits

# Fork Workflow
git remote add upstream <original-url> # Add original as upstream
git fetch upstream                     # Fetch from original
git merge upstream/main                # Merge original changes
git push origin main                   # Update your fork

Key Takeaways

  • git clone downloads a complete copy of a repository
  • Cloning automatically sets up the origin remote
  • Forking creates a copy on GitHub; cloning creates a copy on your computer
  • Fork-and-clone workflow is standard for contributing to open source
  • Always add upstream remote when working with forks
  • Read the README after cloning to understand setup requirements
  • Use --depth 1 for faster clones of large repositories
  • You can clone your own repositories on multiple computers
  • Create feature branches after cloning, don't work on main directly
  • Keep forks updated by regularly fetching and merging from upstream

What's Next?

Excellent work! You now know how to clone repositories, understand the fork-and-clone workflow, and can work with existing projects from GitHub. You're ready to contribute to any repository!

In the next lesson, we'll dive into GitHub README & Documentation. You'll learn how to write effective README files, master Markdown formatting, create professional project documentation, and make your repositories stand out. Good documentation is crucial for collaboration and showcasing your work!

🎯 Practice Assignment

Before the next lesson, practice cloning:

  1. Clone one of your own repositories on a different computer or folder
  2. Find an interesting open-source project and fork it, then clone your fork
  3. Add the original repository as upstream and practice fetching updates
  4. Explore the repository structure, branches, and commit history
  5. Try a shallow clone of a large repository to see the speed difference
  6. Read the README and try to run the project locally

Test Your Understanding of Cloning Repositories

Question 1 of 4

What does 'git clone' do?

Current Score0 / 0

Know someone who'd find this guide helpful? Please share!

Previous
Pushing & Pulling Code
Next
GitHub README & Documentation

Never Miss a New Git & GitHub Tutorial

Join 2,000+ developers learning Git & GitHub step-by-step. Get new tutorials, tips, and exclusive resources delivered to your inbox - completely FREE.

You might also like

UI Components

Ready-made components for your projects

Developer Tools

Boost productivity with handy generators

HTML Game

Learn HTML concepts through interactive gameplay

Join Our Web Development Training Program

Master frontend & backend development with hands-on projects.

Git & Github Tutorials

0 of 20 completed

Your Progress0%

Topics

Getting Started

  • What is Git?
  • What is GitHub?
  • Installing & Configuring Git
  • Your First Git Repository

Core Git Concepts

  • Understanding Commits & History
  • Working with Branches
  • Merging Branches
  • The Staging Area
  • Undoing Changes

Working with GitHub

  • Connecting to GitHub
  • Pushing & Pulling Code
  • Cloning Repositories
  • GitHub README & Documentation

Collaboration Workflows

  • Forking & Pull Requests
  • Code Review Basics
  • Handling Merge Conflicts
  • Issues & Project Management

Best Practices & Workflows

  • Git Workflow Best Practices
  • Working with .gitignore
  • Common Git Problems & Solutions
Falytom logoFALYTOM

Learn technologies like HTML, CSS, JavaScript, React, NodeJS and more through interactive games, tutorials, components and free tools. Transform your businesses with AI chatbots, SEO-optimized websites, and professional development services.

© 2025 Tomilola Group
  • Facebook logo
  • Twitter logo
  • Instagram logo
  • LinkedIn logo
  • GitHub logo
  • YouTube logo