GIT WORKFLOWS / LESSON 03
Fork Workflow.
Contributing to projects you don't own

Loading the lesson…
Loading activities…
GIT WORKFLOWS / LESSON 03
Contributing to projects you don't own

Loading the lesson…
Loading activities…
What if you find a bug in somebody else's project and want to fix it? Or you've got a great idea for a feature in an open source tool? You can't just push changes to their repository, because you don't have permission.
That's where forking comes in. A fork is your own copy of someone else's project, and you can do whatever you want with it. Then, if you'd like your changes to land in the original project, you ask nicely with a pull request.
A fork is a complete copy of a repository that lives in your own GitHub account. It stays connected to the original (called the "upstream" repository), but it's yours to change.
Picture it like this. You can't scribble in someone else's notebook, but you can photocopy it, write in your copy and then show them what you added. If they like it, they can add it to their original.
Building stuff with other people is honestly the best part of all this. Most of my free tools, like the A2P checker, the email and DNS deliverability checker and the Bulk Image Processor, got built alongside friends... and sharing work back and forth is exactly what this workflow is made for.
The fork workflow follows a clear pattern. Let's walk it.
On GitHub, go to the project you want to help with. Click the "Fork" button in the top right corner.
GitHub makes a copy in your account. If the original was cooldev/awesome-project, your fork is yourusername/awesome-project.
Clone your fork (NOT the original) to your computer.
That gives you a local copy of your fork. We're using the SSH address you set up in the GitHub module, so pushing back to your fork just works.
Hook up to the original repository so you can pull in its updates.
Now you've got two remotes.
origin - Your forkupstream - The original projectNever work straight on main. Make a branch for your changes.
Pick a clear name that says what you're doing.
Do the work. Fix that bug. Add that feature. Then commit.
Push your branch up to your fork on GitHub.
Notice we push to origin (your fork), not upstream (the original).
Head to your fork on GitHub. You'll see a prompt to create a pull request. Click it!
Your pull request asks the original project to pull in your changes. The maintainers review it and decide whether to merge it.
The original project keeps moving while you work, so you'll want to sync your fork regularly to dodge conflicts.
Grab the latest changes from the original project.
Switch to your main branch and merge.
Update your fork on GitHub.
Let's walk through a real scenario. You spotted a typo in the docs for a project called recipe-app.
Go to github.com/chefmaster/recipe-app and click Fork. Now you've got yourusername/recipe-app.
Double-check your remotes.
You should see both origin and upstream in the list.
Open the README, fix the typo and save the file.
Go to GitHub, create the pull request and write a nice description of what you fixed.
When you open a pull request on someone else's project, keep these in mind.
The fork workflow is how most open source software gets built. Anybody can pitch in on any public project, and you don't need permission to get started. You fork, make your changes and ask if they want them.
This model has produced some seriously impressive software.
Most of these take contributions through forks and pull requests on GitHub. Linux is the odd one out (the kernel takes patches over email instead of GitHub pull requests), but the idea of copy, change and propose is exactly the same.
Here are the key commands for the fork workflow.
| Command | What it does |
|---|---|
git clone url | Clone a repository to your computer |
git remote add upstream url | Add the original repo as upstream |
git remote -v | List all your remotes |
git fetch upstream | Get updates from original repo |
git merge upstream/main | Merge upstream changes into your branch |
git push origin branch | Push your changes to your fork |
upstream to stay connected to the original projectorigin (your fork) and pull from upstream (the original)Now you know how forking works, so let's go further into open source. Next lesson covers how to find good projects to contribute to and how to be a great community member...