How to clone a Git repository
· Category: Git
Short answer
Run git clone <url> to download a full copy of a remote repository to your local machine.
Steps
- Clone via HTTPS:
git clone https://github.com/user/repo.git
- Clone via SSH:
git clone [email protected]:user/repo.git
- Clone into a specific folder:
git clone https://github.com/user/repo.git my-folder
- Clone a specific branch:
git clone --branch main --single-branch https://github.com/user/repo.git
Tips
- SSH cloning requires your public key to be added to the remote server.
- Use
--depth 1for a shallow clone if you only need the latest commit. git clone --recursivealso clones submodules.
Common issues
- Authentication failures: check your SSH key or personal access token.
- Large repositories: shallow clones or sparse checkouts can save time and disk space.