How to clone a git repository

Last updated: April 1, 2026

Quick Answer: Open your terminal and run git clone [repository-url] to download a copy of the repository to your local machine, creating a new directory with all project files and version history.

Key Facts

Overview

Git clone is a fundamental command for developers that creates a local copy of a remote Git repository. This operation downloads all project files, commit history, and branches from a remote server to your computer. Cloning is the standard way to start working on an existing project, as it provides you with a complete development environment including all version control information.

Basic Clone Command

The basic syntax is simple: open your terminal or command prompt and type git clone [repository-url]. Replace [repository-url] with the actual URL of the repository you want to clone. For example: git clone https://github.com/username/repository-name.git. The command will create a new directory with the repository name in your current location and download all files and history into that directory.

HTTPS vs SSH Clone

Repositories can be cloned using either HTTPS or SSH URLs. HTTPS URLs, like https://github.com/username/repo.git, are simpler to use and work without additional setup, though they may require you to enter credentials. SSH URLs, like git@github.com:username/repo.git, require SSH keys to be configured on your machine but offer more secure authentication. Choose based on your preference and whether you have SSH keys set up for your Git hosting service.

Customizing the Clone Directory

By default, Git creates a directory with the repository's name. To specify a custom directory name, add it after the repository URL: git clone [repository-url] [directory-name]. This is useful when you want to rename the repository locally or clone into a specific project folder. For example: git clone https://github.com/user/repo.git my-project will create a directory called 'my-project' instead of 'repo'.

Cloning Specific Branches

By default, cloning downloads all branches but only checks out the default branch (usually main or master). To clone a specific branch only, use: git clone --branch [branch-name] [repository-url] or the shorter form git clone -b [branch-name] [repository-url]. This is useful for saving bandwidth and time when you only need a specific branch. After cloning, you can switch to other branches using git checkout if they exist on the remote.

Related Questions

What's the difference between cloning and forking a repository?

Cloning creates a local copy of a repository on your machine for development, while forking creates a separate copy on the Git hosting platform (like GitHub) under your account. Forking is typically used when contributing to open-source projects, allowing you to make changes without affecting the original repository.

How do I clone a private repository?

For private repositories, ensure you have access permissions and use SSH authentication with configured SSH keys, or HTTPS with a personal access token. Run git clone with the private repository URL, and Git will prompt for authentication if needed.

How do I update a cloned repository with the latest changes?

Navigate to your cloned repository directory and run <strong>git pull</strong> to fetch and merge the latest changes from the remote repository. This updates your local files to match the current state of the remote without re-cloning the entire project.

Sources

  1. Git Documentation - git clone GPL-2.0
  2. Wikipedia - Git (software) CC-BY-SA-4.0