git clone — Copying a Repository
The git clone command creates a local copy of a remote repository. It downloads all commits, branches, and files, and sets up a connection back to the source.
What Clone Does
- Creates a new directory
- Initializes a Git repository inside it
- Adds the source as a remote called
origin - Downloads all commits and branches
- Checks out the default branch (usually
main)
Basic Usage
git clone https://github.com/user/project.git
Try it!
Clone a simulated remote repository:
- Clone the repo:
git clone https://github.com/example/project.git - Check the remote:
git remote -v - View the commit history:
git log --oneline - List files:
ls
Notice that git remote -v shows origin pointing to the URL you cloned from.
After Cloning
Once cloned, you can:
- Make changes and commit locally
- Push your commits back with
git push - Pull updates from others with
git pull
The clone is a full copy — you have the entire history, not just the latest files.