How to Clone a Git Repository
Cloning creates a local copy of a remote Git repository, including its files, branches, and commit history. This guide shows the standard clone command, how to choose an HTTPS or SSH URL, and what to check when cloning fails.
Practice Git workflows →Before you clone
Copy the repository URL from its hosting page. On GitHub, use the green Code menu and choose HTTPS or SSH. You need access to the repository; private repositories require you to authenticate with an account that has permission.
Open a terminal in the parent folder where you want the new project directory to live. Avoid cloning into an existing project folder unless you have checked what is already there.
Clone a repository with the git clone command
Run git clone followed by the URL you copied:
git clone https://github.com/OWNER/REPOSITORY.gitReplace OWNER and REPOSITORY with the values in the actual URL. Git creates a directory named after the repository, downloads its history, and checks out the default branch.
Enter the new directory and confirm the working tree and remote:
cd REPOSITORY
git status
git remote -vClone into a specific folder
Add a destination name after the repository URL to choose the local folder:
git clone https://github.com/OWNER/REPOSITORY.git my-projectGit creates my-project inside your current directory. The destination normally must not already exist, or must be empty. Choose a distinct path to avoid mixing the clone with unrelated files.
Clone with HTTPS or SSH?
Both URL types work with Git. HTTPS is often the easiest way to get started. When a host requires authentication, use its supported sign-in flow or credential manager; most hosts no longer accept an account password for Git over HTTPS. Never paste an access token into a command that might be saved in shell history or shared.
SSH is convenient for repeated work if you have created an SSH key and added its public key to your hosting account. An SSH clone URL commonly looks like git@github.com:OWNER/REPOSITORY.git. If SSH reports permission denied, check that the correct public key is registered and that your SSH agent can use the matching private key.
Common git clone errors and fixes
Repository not found or access denied
Check the URL for typos and confirm the repository still exists. For a private repository, make sure you are signed in with an account that has access. A private repository can appear unavailable when the account or credentials are wrong.
Permission denied (publickey)
This usually means the SSH server did not accept a key from your machine. Confirm the clone URL is the SSH version, then check your host account’s registered SSH keys and local agent. If you have not set up SSH, use the HTTPS URL instead.
Destination path already exists
Choose another destination folder or inspect and safely move the existing files first. Do not delete a folder until you have verified it contains no work you need.
Fatal: not a git repository
After cloning, change into the directory Git created before running repository commands. See the guide to fixing “not a git repository” if the error continues.
Clone a particular branch
To clone only one branch and its history, use --branch with --single-branch:
git clone --branch BRANCH_NAME --single-branch https://github.com/OWNER/REPOSITORY.gitReplace BRANCH_NAME with an existing branch name. If you need other branches later, fetch them or clone the full repository instead.
What to do after cloning
Inspect the project instructions before installing dependencies or running commands. Then check your current branch and working tree:
git branch --show-current
git statusTo make a separate line of work, follow the guide to creating a Git branch. A clone is a full local repository, so you can create commits, switch branches, and fetch updates from its remote.
Frequently asked questions
What is the difference between git clone and git pull?
git clone creates a new local copy of a repository.git pull fetches and integrates updates into a repository you already cloned.
Does cloning change the remote repository?
No. Cloning downloads a copy to your computer. It does not change remote files or history.