Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How to Clone a Git Repository

Updated November 30, 2026 · Written and reviewed under our editorial policy

To clone a Git repository, copy its URL (on GitHub: the green Code button), open a terminal in the folder where you want it, and run git clone <url>. Git creates a new folder named after the repository. Add a folder name after the URL to choose the name, or --depth 1 to download only the latest commit.

To clone a repository from the command line:

  • Install Git and check it with git --version.
  • Copy the repository URL (HTTPS or SSH).
  • Open a terminal and cd to the parent folder.
  • Run git clone https://github.com/owner/repo.git.
  • Run cd repo to start working.

Source: Git documentation, "git-clone" (git-scm.com/docs/git-clone), checked 2026-11-28.

If git --version prints an error instead of a version number, install Git before you start.

Command Prompt showing git clone output for a GitHub repository

Clone with HTTPS or SSH

A Git repository can be cloned over HTTPS or over SSH, and GitHub shows both URLs under the green Code button. Both download the same files; the difference is how you sign in to a private repository and when you push.

  • HTTPS (https://github.com/owner/repo.git): needs no setup for a public repository. For a private repository or a push, Git asks for credentials; on GitHub that's a personal access token, which a credential helper can store for you.
  • SSH (git@github.com:owner/repo.git): needs an SSH key on your computer, with its public key added to your GitHub account. After that, Git doesn't ask for your GitHub password (it may ask for your key's passphrase unless ssh-agent or Keychain stores it). Test the setup with ssh -T git@github.com.

Pick HTTPS if you only need to read the code, or if your network blocks SSH. Pick SSH if you push often from your own computer. Any terminal works for this; we compared the best terminal apps for Mac.

Cloned a project and want to know if it still works? Kane CLI runs end-to-end tests from your terminal and works alongside Claude Code, Cursor, Codex and Gemini CLI. Use it to run end-to-end tests on the repo you just cloned.

GitHub Code button showing the HTTPS clone URL

Clone into a specific folder

By default, git clone creates a folder named after the repository, so cloning owner/repo.git gives you a folder called repo. To choose the folder name, add it after the URL:

git clone https://github.com/owner/repo.git my-folder

To clone into the folder you're already in, use a dot as the folder name: git clone <url> .. Git only clones into a folder that doesn't exist yet or is empty, so this works in a new, empty folder.

If the repository has no ignore rules yet, generate a .gitignore file so build output and local secrets stay out of your commits. Once the folder exists, you can run the project's Python scripts from it.

Clone one branch

To clone one branch of a Git repository, name it with --branch and add --single-branch:

git clone --branch dev --single-branch https://github.com/owner/repo.git

On its own, --branch still downloads every branch; it only changes which one is checked out after the clone. --single-branch fetches just that branch's history, which saves time on repositories with many long-lived branches. --branch also accepts a tag, such as a release tag.

To add another branch to a single-branch clone later, run git remote set-branches --add origin other-branch, then git fetch origin other-branch. Branches you no longer need can be deleted locally and on the remote.

Shallow clone for CI

A shallow clone downloads only the most recent commits of a Git repository instead of its full history. --depth 1 fetches just the latest commit:

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

--depth implies --single-branch, so you get only the default branch, or the one you name with --branch. That makes a shallow clone a good fit for CI jobs and for a quick look at a large repository. The trade-offs:

  • History: git log and git blame stop at the cut-off, so you can't see older changes.
  • Tools that read history: changelog generators and versioning scripts that look at older commits or tags may fail or give wrong results.
  • Going back to a full clone: run git fetch --unshallow to download the rest of the history.

Clone a private repository

Cloning a private Git repository uses the same git clone command, but Git has to prove you have access. You have two options:

  • HTTPS with a personal access token: create a token on GitHub under Settings > Developer settings > Personal access tokens, with access to the repository. When git clone asks for a password, paste the token. Git for Windows includes Git Credential Manager, which can sign you in through the browser and store the credentials instead.
  • SSH with a key: run ssh-keygen -t ed25519 -C "you@example.com", add the contents of the new .pub file on GitHub under Settings > SSH and GPG keys, then clone with the SSH URL.

Never paste a token into a URL you share. A URL such as https://<token>@github.com/owner/repo.git is saved in your shell history and in the clone's .git/config file, where anyone who reads it can use the token.

Clone in VS Code and GitHub Desktop

VS Code and GitHub Desktop can both clone a Git repository without typing commands. VS Code uses the Git installed on your computer; GitHub Desktop comes with its own.

VS Code

  • Open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on Mac) and run Git: Clone.
  • Paste the repository URL and press Enter, or pick Clone from GitHub to browse your repositories.
  • Choose a parent folder, then click Open when VS Code offers to open the cloned repository.

GitHub Desktop

  • Click File > Clone repository.
  • Pick the repository on the GitHub.com tab, or paste its address on the URL tab.
  • Check the Local path and click Clone.

Both tools also list the repository's branches, so you can switch, create or delete a Git branch without the command line.

Fix common errors

Most failed Git clones come down to one of these errors:

  • fatal: destination path 'repo' already exists and is not an empty directory: the target folder already has files. Clone under a new name (git clone <url> repo-2), rename or delete the old folder, or, if it's already a clone of the same repository, cd into it and run git pull.
  • Permission denied (publickey): GitHub didn't accept an SSH key from your computer. Run ssh -T git@github.com to test, check that your public key is added to your account, or clone with the HTTPS URL instead.
  • Repository not found: the URL is wrong, or the repository is private and the account you signed in with can't see it. Copy the URL again from the Code button and check which account your credentials belong to.
  • 'git' is not recognized or git: command not found: Git isn't installed, or the terminal was opened before it was. Open a new terminal and try again.

If git isn't recognized, install Git on your computer first. To check how well you know clones, remotes and branches, work through our Git interview questions.

Frequently Asked Questions

What does git clone do?

git clone copies a repository and its history into a new folder on your computer. It also sets up a remote named origin, so you can pull new commits and push your own later.

How do I clone a specific branch?

Run git clone --branch <name> --single-branch <url>. --branch checks out that branch after the clone, and --single-branch skips downloading the other branches.

Is git clone the same as git pull?

No. git clone makes a new copy of a repository, once. git pull updates a copy you already have with the new commits from the remote.

How do I clone into the current folder?

Run git clone <url> . with a dot at the end. The current folder must be empty, or Git refuses to clone into it.

Why does git clone ask for a password?

The repository is private, or the URL points to one your account can't see, so GitHub asks you to sign in. GitHub doesn't accept your account password for Git over HTTPS: enter a personal access token, sign in through Git Credential Manager, or clone with an SSH URL and a key instead.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests