Two of the most frequent ways to obtain code on GitHub are cloning and forking. While both involve copying a repository, they serve distinct roles in open-source development and enterprise collaboration.
1. Cloning a Repository: git clone
Cloning downloads an entire existing Git repository from a remote server (like GitHub) to your local computer:
It downloads all files, directories, commits, and branches.
It automatically configures the remote alias named origin pointing back to the cloned URL.
It automatically checks out the default branch (main).
1# Clone using SSH URL (Recommended)
2git clone git@github.com:facebook/react.git
3
4# Or clone using HTTPS URL
5git clone https://github.com/facebook/react.git
Cloning into a Custom Directory Name:
By default, Git creates a folder named after the repository (react). You can specify a custom directory name as the last argument:
For massive repositories (like Linux or Chromium) with 15 years of history, downloading every commit can take hours and gigabytes of disk space. A shallow clone downloads only the latest snapshot:
What if you want to contribute to an open-source project (like vuejs/core or django/django), but you are not an employee and do not have write access to push commits to their repository? This is where Forking comes in!
1Original Upstream Repo Your Personal Fork on GitHub