Introduction to Forking: Master Open Source Collaboration
Learn how to fork a repository on GitHub to contribute to open source projects. Master the essential workflow for personal copies and collaborative development.

Previously in this course, we covered cloning repositories to pull existing code onto your local machine. While cloning gives you a local copy of a project, it doesn't grant you "write" access to someone else’s remote repository. Today, we add the concept of forking to our toolkit, which provides a server-side, personal copy of a project, enabling you to contribute to open source software without needing direct permission from the original maintainers.
What is Forking and Why Use It?
In the Introduction to GitHub, we discussed how GitHub acts as a central hub for code. When you want to fix a bug or add a feature to a project you don't own, you cannot simply push your changes to the original repository; GitHub will (rightly) reject your attempt because you lack the necessary permissions.
Forking is GitHub's solution to this. It creates a complete, independent copy of a repository under your own GitHub account.
- Independence: Because the fork lives under your namespace (e.g.,
github.com/your-username/project-name), you have full write access to it. - Collaboration: You can make changes, commit them to your fork, and then request that the original project maintainers "pull" those changes into their repository. This request is known as a Pull Request (PR).
- Safety: Forking decouples your experimental changes from the original project's history, allowing you to iterate safely without disrupting the upstream work.
The Forking Flow
Think of forking as "cloning on the server." When you clone, you bring code to your computer. When you fork, you tell GitHub to duplicate a repository from one user's space into yours.
Flow diagram: Original Repo -- Forking → Your GitHub Fork; B -- Cloning → Your Local Machine; C -- Pushing → Your GitHub Fork
How to Fork a Repository

Forking is done entirely through the GitHub web interface.
- Navigate to the repository you wish to contribute to on GitHub.
- Locate the "Fork" button in the top-right corner of the page.
- Click it. GitHub will prompt you to choose an owner (your account) and an optional name for the fork.
- Wait a few seconds while GitHub clones the repository into your account.
Once the process finishes, you will see a new repository in your dashboard that looks identical to the original, but lives at github.com/your-username/repository-name.
Worked Example: Contributing to a Project
Suppose you want to contribute a documentation fix to a popular project.
- Fork: Navigate to the project page and click Fork.
- Clone your fork: Instead of cloning the original, run:
git clone https://github.com/your-username/project-name.git - Modify: Create a new branch, make your edits, and commit them.
- Push: Push your changes to your fork:
git push origin feature-branch - Request: Visit your fork on GitHub. You will see a prompt to "Compare & pull request." Clicking this creates the bridge between your fork and the original repository.
Hands-on Exercise
To practice this, find a "hello-world" or "test" repository on GitHub (or use a friend's public project).
- Fork the repository to your own account.
- Clone your new fork to your local machine.
- Use
git remote -vin your terminal. Observe thatoriginpoints to your fork, not the original repository. - Create a file called
contribution.txt, add it, commit it, and push it to your fork. - Verify the file appears on your GitHub fork page but not on the original repository's page.
Common Pitfalls
- Confusing Cloning with Forking: Cloning is for local development; forking is for server-side ownership. You almost always fork before you clone when contributing to external projects.
- Pushing to Upstream: Beginners often try to add the original repository as
originand push to it. This will fail with a403 Forbiddenerror. Always setoriginto your fork. - Stale Forks: Once you fork, your copy does not automatically update when the original project changes. You must learn to sync your fork (which we will cover in the next lesson).
FAQ
Does forking copy the history? Yes, a fork is a full copy of the repository, including all branches, tags, and the entire commit history.
Can I fork my own repositories? Yes, though it is rarely useful. Forking is primarily a mechanism for cross-user collaboration.
If I delete my fork, does it delete the original? No. Your fork is entirely independent. Deleting it has no impact on the original repository or other people's forks.
Recap
Forking is the foundational step for external contribution. By creating a personal copy of a repository, you gain the autonomy to experiment, develop, and eventually propose changes back to the original project via Pull Requests. It is the core mechanism that powers the collaborative, distributed nature of open source software.
Up next: Syncing Your Fork — learn how to keep your personal copy up-to-date with the original project.



