Clone
Copy a remote repository to your local machine
Overview
git clone downloads a repository including its full history, branches, and remote configuration. It is the standard way to start working on an existing project from GitHub, GitLab, or another host.
Syntax / Usage
# HTTPS clone
git clone https://github.com/user/project.git
# SSH clone (requires SSH key)
git clone git@github.com:user/project.git
# Clone into specific folder
git clone https://github.com/user/project.git my-project
# Shallow clone (less history, faster)
git clone --depth 1 https://github.com/user/project.git
# Clone specific branch
git clone -b develop --single-branch git@github.com:user/project.git
After cloning:
cd project
git remote -v # origin points to source
git branch -a # all branches
git switch main
Examples
Clone and install a Node project:
git clone git@github.com:stackademic/stackademic-v2.git
cd stackademic-v2
yarn install
cp .env.example .env.local
Clone your fork and add upstream:
git clone git@github.com:you/open-source.git
cd open-source
git remote add upstream git@github.com:org/open-source.git
Common Mistakes
- Cloning into a non-empty directory without
git clone .patterns - Using HTTPS without credential helper and failing pushes
- Forgetting to run project setup after clone (deps, env files)
- Cloning the wrong repo URL (fork vs upstream)
See Also
remote branch commit stash