Difficulty: Beginner
What is the difference between a fork and a branch? When would you use each in open-source contributions?
A fork is a server-side copy of an entire repository under your GitHub account, while a branch is a lightweight pointer to a specific commit within a single repository.
Forks are used when you don't have write access to the upstream repository — which is the case for most open-source contributions. You fork the repository, clone your fork, make changes, and submit a PR from your fork's branch to the upstream repository. The fork serves as your personal workspace.
Branches are used within a repository to isolate changes. In a forked repository, you create branches for each feature or fix you're working on. In the upstream repository, maintainers use branches to manage their development workflow.
If you have write access (e.g., within your team's repository), you can work directly in branches without forking. But for external open-source contributions, the fork-and-PR model is standard because it respects the maintainers' control over their repository.
Fork, Branch, Permissions, Collaboration Model