git clone
Create a local copy of a remote repository, downloading all commits, branches, and files to start working.
You've found a repository on GitHub you want to work on, or your team just
created a new project and you need a local copy. git clone downloads an entire
repository from a remote server to your machine, creating a complete working
copy with all commits, branches, and history. It's the starting point for
contributing to any Git project that lives remotely.
The basic syntax is git clone https://github.com/user/repository.git, which
creates a new directory named after the repository, downloads all the data, and
checks out the default branch (usually main). You can specify a different
directory name with git clone https://github.com/user/repo.git my-folder. The
URL can be HTTPS (like the example) or SSH (git@github.com:user/repo.git),
depending on how you've configured authentication.
After cloning, Git automatically sets up a remote called origin pointing to the URL you cloned from. This connection lets you fetch updates, push commits, and stay synchronized with the remote repository. Your local repository is a complete copy—you have all commits, tags, and history locally, not just the latest version.
Shallow Clones and Performance
For very large repositories with extensive history, cloning everything can be
slow. Running git clone --depth 1 https://github.com/user/repo.git creates a
shallow clone with only the most recent commit, ignoring all history. This
downloads much faster and uses less disk space, which is useful for CI/CD
environments where you just need the current code. The tradeoff is you can't
access historical commits or see the full log until you "deepen" the clone
later.
You can also clone a specific branch with
git clone --branch feature-name --single-branch https://github.com/user/repo.git,
which only downloads that branch's history instead of all branches. This saves
time in repositories with many feature branches when you only need one.
Working with Forks
When contributing to open source projects, you typically fork the repository on
GitHub, then clone your fork. The workflow is: fork on GitHub, clone your fork
with git clone https://github.com/yourname/repo.git, then add the original
repository as an upstream remote with
git remote add upstream https://github.com/original/repo.git. This setup lets
you push to your fork while pulling updates from the original project.
Understanding clone means understanding that you're creating a full-fledged repository, not just downloading files. You can make commits, create branches, and work offline. The repository is yours to modify, with origin tracking where it came from so you can sync changes later. Cloning is usually a one-time operation per project—you clone once, then use fetch and pull to stay updated.
