4Geeks chosen to deliver AI education in the Bahamas alongside Harvard, Oxford, and Columbia.See more

How to clone a github repository

By 4Geeks

Copy a GitHub repository to your computer with git clone, access private repositories, fork projects and fix the errors you may see.

6 min readLast updated
GitHub logo

How do you clone a GitHub repository?

Short answer: on the repository page, click the green Code button and copy the URL. Then open a terminal in the folder where you want the project and run git clone followed by that URL. Git downloads every file and the whole history into a new folder named after the repository.

bash
git clone https://github.com/4GeeksAcademy/html-hello
cd html-hello

You need Git installed. Without the terminal, you can also clone with GitHub Desktop or from VS Code.

git clone downloads the repository, origin already points to GitHub and the project is ready to open.

Every way to clone a repository

What you wantCommand or tool
Clone with HTTPS (the usual way)git clone https://github.com/user/repo
Clone with SSHgit clone git@github.com:user/repo.git
Clone with the GitHub CLIgh repo clone user/repo
Choose the folder namegit clone https://github.com/user/repo my-folder
Clone into the current empty foldergit clone https://github.com/user/repo .
Clone one branchgit clone -b develop https://github.com/user/repo
Only the latest version, without historygit clone --depth 1 https://github.com/user/repo
Include submodulesgit clone --recurse-submodules https://github.com/user/repo
Without the terminalGitHub Desktop, or VS Code: Git: Clone

Clone a repository step by step

1. Copy the URL. Open the repository on GitHub, click Code and copy the URL from the HTTPS tab.

2. Open a terminal in the right folder. Use Terminal on Mac or Linux, or Git Bash or PowerShell on Windows. Move to the folder where you keep your projects:

bash
cd ~/projects

3. Run git clone with the URL you copied:

bash
git clone https://github.com/4GeeksAcademy/html-hello
# Cloning into 'html-hello'...
# Resolving deltas: 100% (55/55), done.

4. Enter the folder and check it:

bash
cd html-hello
git remote -v
# origin  https://github.com/4GeeksAcademy/html-hello (fetch)
# origin  https://github.com/4GeeksAcademy/html-hello (push)

The remote origin points to GitHub, so git pull brings new changes and git push sends yours, if you have permission. Open the folder in your editor and start working.

Career · AI Engineering

You already clone real projects, now build with AI

From zero to junior AI Engineer: Python, data, AI agents and RAG with mentors and real projects.

Clone a private repository: HTTPS or SSH

Public repositories clone without logging in. For a private one, GitHub needs to know who you are, and your GitHub password doesn't work in the terminal: GitHub removed password authentication for Git in 2021.

You have three options:

  • GitHub CLI (easiest). Run gh auth login once, then gh repo clone user/repo.
  • HTTPS with a token. Create a personal access token in GitHub under Settings → Developer settings. When Git asks for a password, paste the token. Git Credential Manager, included with Git for Windows, can also open the browser to log you in.
  • SSH. Create a key once and add it to GitHub:
bash
ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub      # copy this and add it in GitHub → Settings → SSH keys
ssh -T git@github.com          # Hi user! You've successfully authenticated...
git clone git@github.com:user/repo.git

Clone vs fork

CloneFork
What it doesCopies a repository to your computerCopies a repository to your GitHub account
WhereLocalOn GitHub
When to use itTo work on a project you can push to, or just to read and run itTo propose changes to a project you can't push to

They are often used together: fork the project on GitHub, then clone your fork.

Fork and clone a repository

  1. On the repository page, click Fork and create the fork in your account.
  2. Clone your fork, not the original:
bash
git clone https://github.com/your-user/repo
cd repo
git remote add upstream https://github.com/original-user/repo

upstream lets you bring in the latest changes from the original project with git pull upstream main. With the GitHub CLI, gh repo fork original-user/repo --clone does the three steps at once.

Clone without the terminal

GitHub Desktop: on the repository page, click Code → Open with GitHub Desktop, or in the app go to File → Clone repository, choose the repository and the local folder, and click Clone.

VS Code: open the Command Palette with Ctrl + Shift + P (Cmd + Shift + P on Mac), run Git: Clone, paste the URL and choose a folder. VS Code offers to open the project when it finishes.

What to do after cloning

bash
cd repo
git status                  # On branch main, nothing to commit
git switch -c my-change     # work on your own branch
npm install                 # or pip install -r requirements.txt, if the project has dependencies
git pull                    # bring the latest changes later

Read the project's README.md first: it usually explains how to install and run it.

Use AI to clone and set up a project

An assistant like ChatGPT, Claude or GitHub Copilot can guide you through a clone that fails or a project that doesn't run. These three prompts are ready to copy.

1. Fix a failed clone

I run git clone [the URL] on [Windows / Mac / Linux] and get this error:
[paste the error].
Explain what it means and give me the steps to fix it.

2. Set up access to a private repository

I need to clone a private GitHub repository on [Windows / Mac / Linux].
Explain step by step how to do it with [SSH / a personal access token / the GitHub CLI].

3. Run the project I cloned

I cloned this repository: [the URL]. This is its README: [paste it].
Tell me the commands to install it and run it on [your system].

Never paste a token or a private key into a chat. If an answer asks for one, stop and set it up in your terminal instead.

Learn with a mentor

From cloning repositories to AI applications

In the 4Geeks AI Engineering career program you start with no experience and finish with AI agents and RAG systems in your portfolio.

Common problems when cloning

What you seeWhy it happensFix
git: command not found or 'git' is not recognizedGit is not installedInstall Git and open a new terminal
fatal: destination path 'repo' already exists and is not an empty directory.You already have a folder with that nameClone into another name: git clone <url> repo-2
Git asks for a username, or says Repository not foundThe URL is wrong, or the repository is private and you have no accessCheck the URL and your access, and log in with gh auth login or a token
Support for password authentication was removedYou typed your GitHub passwordUse a personal access token, SSH or the GitHub CLI
Permission denied (publickey)Your SSH key isn't added to GitHubAdd ~/.ssh/id_ed25519.pub in GitHub → Settings → SSH keys
The clone is very slow or too bigThe repository has a long historygit clone --depth 1 <url>
Folders of submodules are emptySubmodules aren't downloaded by defaultgit submodule update --init --recursive
Free download

Cloning GitHub repositories in a 2-page cheat sheet

Every git clone option, HTTPS, SSH and the GitHub CLI, private repositories, clone vs fork, what to do after cloning, common errors and prompts for ChatGPT, Claude or Copilot. Free, in PDF.

How to clone a GitHub repository cheat sheet

2 pages · PDF · 4Geeks

  • Every git clone option in one table
  • Access to private repositories, step by step
  • Common errors and prompts to solve them with AI

Get it free

Your PDF right away

Frequently asked questions about cloning GitHub repositories

Want to go from cloning repositories to building AI applications, with real projects and mentors?

See the AI Engineering program