Git Fork & Contribute
In this page:
What is a Fork?
A fork is a full copy of someone else's repository under your own account, including its entire history, that you're free to modify however you like without needing any permission on the original. It's the standard entry point for contributing to a project you don't have push access to.
Example: What is a Fork?
git clone https://github.com/yourname/repo.git
Adding the Upstream Remote
By default your fork only knows about itself — adding the original repository as a remote named upstream (git remote add upstream <url>) gives you a way to fetch new commits from the project you forked from, which your fork doesn't get automatically just by existing.
Example: Adding the Upstream Remote
git remote add upstream https://github.com/original/repo.git
Syncing your Fork
Since your fork is a snapshot from when you created it, the original project keeps moving without you unless you deliberately sync — fetching from upstream and merging (or rebasing) those changes into your local branch keeps your fork from drifting too far out of date to merge back cleanly later.
Example: Syncing your Fork
git fetch upstream
git checkout main
git merge upstream/main
Pushing Changes to your Fork
Your fork on the hosting platform is typically the origin remote, so after committing locally you push to origin (your fork) exactly as you would with any repository you own — this is what makes your branch visible and available for opening a pull request.
Example: Pushing Changes to your Fork
git push origin feature-x
Opening a Pull Request from a Fork
With your branch pushed to your fork, opening a pull request on the hosting platform's website targets the original repository as the destination and your fork's branch as the source — this is the actual proposal that a maintainer reviews and merges.
Example: Opening a Pull Request from a Fork
git push origin feature-x
# then open a pull request from yourname:feature-x to original:main
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: