How to Clone a Git Repository
current stable releases (Python 3.12+, Node 22, Git 2.4x) on Mac, Linux, and Windows · Last checked · Suggest an edit
https://instructions.wiki/coding/clone-a-git-repository
You found a repository on GitHub, GitLab, or another host and want a local copy with its full history. git clone downloads it in one command.
Copy the repository URL
On GitHub, open the repository page and click the green Code button. Pick either the HTTPS or SSH tab and copy the URL.
HTTPS looks like https://github.com/user/repo.git. It works everywhere and asks for credentials when you push to a private repository.
SSH looks like git@github.com:user/repo.git. It requires an SSH key added to your account but never prompts for a password afterward.
If you are not sure, use HTTPS. The choice can be changed later with git remote set-url origin.
Run git clone
git clone https://github.com/user/repo.git
Git creates a folder named after the repository (repo in this case), downloads every commit, and checks out the default branch.
Cloning into 'repo'...
remote: Enumerating objects: 120, done.
Receiving objects: 100% (120/120), done.
Choose the folder name
By default the folder takes the repository's name. To use a different one, add it as a second argument:
git clone https://github.com/user/repo.git my-project
The folder must not already exist, or Git refuses to clone into it.
Move into the folder
cd repo
The clone already has origin set as the remote, so git pull, git push, and git branch all work immediately. Run git log --oneline to see the history you downloaded.
For large repositories. Add --depth 1 to download only the latest commit instead of the full history: git clone --depth 1 URL. The clone is much smaller and faster. Fetch the rest later with git fetch --unshallow if you need it.
If cloning fails with a permission error. Private repositories need authentication. For HTTPS, sign in when prompted (GitHub requires a personal access token, not your account password). For SSH, make sure the key on this machine is added to your account.