Git Clone
The git clone command creates a complete copy of a remote repository onto the local machine. This includes all files, all commit history, all branches, and all configuration. It is the standard way to get a project from GitHub onto a local computer.
Cloning is different from simply downloading a ZIP file. A cloned repository is a fully functional Git repository with the complete history and a pre-configured remote connection back to the original.
Syntax
git clone <repository-url>Finding the Repository URL on GitHub
- Open the repository on GitHub
- Click the green "Code" button
- Choose HTTPS or SSH
- Copy the URL shown
HTTPS URL example: https://github.com/ravikumar/my-website.git
SSH URL example: git@github.com:ravikumar/my-website.git
Basic Clone Example
git clone https://github.com/ravikumar/my-website.gitThis creates a new folder called my-website in the current directory with the complete repository inside it.
Output:
Cloning into 'my-website'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (38/38), done.
Receiving objects: 100% (52/52), 14.22 KiB | 2.37 MiB/s, done.
Clone into a Specific Folder Name
By default, Git creates a folder with the same name as the repository. A different name can be specified:
git clone https://github.com/ravikumar/my-website.git portfolioThis clones the repository into a folder called portfolio instead of my-website.
Clone into the Current Directory
To clone directly into the current folder (without creating a subfolder):
git clone https://github.com/ravikumar/my-website.git .Note: The current directory must be empty for this to work.
What Happens After Cloning
After cloning, the project is ready to use immediately:
# Clone the repository
git clone https://github.com/ravikumar/my-website.git
# Navigate into the cloned folder
cd my-website
# Verify the remote is already set up
git remote -v
# Output:
# origin https://github.com/ravikumar/my-website.git (fetch)
# origin https://github.com/ravikumar/my-website.git (push)
# See the full commit history
git log --oneline
# See all branches (local and remote)
git branch -a
Notice that the remote is already set to origin — there is no need to run git remote add after cloning.
Clone a Specific Branch
By default, cloning checks out the repository's default branch (usually main). A specific branch can be cloned:
git clone -b feature-login https://github.com/ravikumar/my-website.gitShallow Clone — Clone Without Full History
For large repositories where the full history is not needed, a shallow clone gets only the most recent commits:
git clone --depth 1 https://github.com/ravikumar/my-website.gitThe --depth 1 means only the latest commit history is downloaded, making the clone much faster and smaller. This is useful for CI/CD pipelines or when just needing to look at the current state of the code.
git clone vs git init + git remote add
| Scenario | Use |
|---|---|
| Starting a completely new project from scratch | git init → create files → git remote add |
| Copying an existing GitHub repository to work on locally | git clone |
| Joining an existing team project | git clone |
| Contributing to open source | Fork first on GitHub, then git clone the fork |
Cloning a Private Repository
When cloning a private repository, GitHub will ask for credentials. Use a Personal Access Token (PAT) as the password. The URL can also include credentials directly (not recommended for security reasons):
git clone https://username:token@github.com/username/private-repo.gitUpdating a Cloned Repository
After cloning, the latest changes from the remote can always be fetched using:
git pull origin mainSummary
git clone downloads a complete copy of a remote repository including all history, branches, and a pre-configured remote connection. It is the standard way to get a project from GitHub onto a local machine. After cloning, the project is ready to work on immediately — make changes, commit, and push.
