Snowed in today, so you get a bonus post. Sometimes being trapped at home is productive.
A fork is your own copy of someone elseās repository on GitHub. Thatās it. Nothing magical.
I remember the first time I saw āForkā on GitHub and thought it was way more complicated than it actually is. Itās not. Let me save you that confusion.
Fork vs Clone
This trips people up constantly, so letās clear it up:
| Action | What it does | Where it lives |
|---|---|---|
| Fork | Copies a repo to your GitHub account | GitHub (remote) |
| Clone | Downloads a repo to your machine | Your computer (local) |
You typically do both: fork first, then clone your fork. Fork gets you a copy you own, clone gets it on your laptop so you can actually work on it.
When to Fork
Fork when:
- You want to contribute to open source (you canāt push to their repo directly)
- You need to customize something for your own use
- You want to experiment without breaking the original
Donāt fork when:
- You already have write access ā just clone and branch, donāt overcomplicate it
- You only want to read the code ā clone is enough
Iāve seen people fork their own teamās repos when they already had push access. Donāt be that person. It just creates confusion.
Why Bother Forking?
Itās your playground. Break things. Push garbage commits. Nobody cares ā itās your copy.
When Iām learning a new codebase, Iāll fork it just so I can add console.log statements
everywhere without shame.
Customization without waiting. Iāve forked tools to add features I needed right now instead of waiting months for a maintainer to maybe merge my PR. Sometimes you just need it to work your way.
Your backup plan. Projects get abandoned. Repos get deleted. Iāve watched popular tools vanish overnight. If youāve forked it, youāre not stranded when the original disappears.
The open source handshake. This is how contributing works. You canāt push to
kubernetes/kubernetes, but you can push to your-name/kubernetes and ask them nicely to
pull your changes in.
The Workflow
Hereās what it looks like in practice:
# 1. Fork on GitHub (click the Fork button ā top right of the repo page)
# 2. Clone YOUR fork (not the original)
git clone [email protected]:YOUR-USERNAME/repo-name.git
cd repo-name
# 3. Add the original as "upstream" so you can pull their updates
git remote add upstream [email protected]:ORIGINAL-OWNER/repo-name.git
# 4. Verify you've got both remotes
git remote -v
# origin [email protected]:YOUR-USERNAME/repo-name.git (fetch)
# origin [email protected]:YOUR-USERNAME/repo-name.git (push)
# upstream [email protected]:ORIGINAL-OWNER/repo-name.git (fetch)
# upstream [email protected]:ORIGINAL-OWNER/repo-name.git (push)
That upstream remote is important. Without it, you canāt easily pull in updates from the
original project.
Keeping Your Fork in Sync
Hereās the thing ā the original repo doesnāt stop just because you forked it. Theyāre shipping features, fixing bugs, moving on with life. Your fork? Itās frozen in time unless you update it.
Option 1: Merge (The Safe Way)
This is what I recommend for most people:
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Youāll get a merge commit in your history. Thatās fine. Itās honest ā it shows exactly what happened.
Option 2: Rebase (The Clean Way)
If youāre particular about a linear history:
git fetch upstream
git checkout main
git rebase upstream/main
git push origin main --force-with-lease
Fair warning: only rebase if youāre the only one working on your fork. Rebasing rewrites history, and if someone else has pulled from your fork, youāre about to ruin their day.
So Which One?
Merge. Just use merge. Unless you have a specific reason to rebase and you understand the implications, merge is safer and works fine.
When Your Fork Goes Off the Rails
Sometimes you let your fork sit for six months and now itās 200 commits behind with conflicts everywhere. Weāve all been there.
The Nuclear Option
If your fork is a disaster and you just want to start fresh:
git fetch upstream
git checkout main
git reset --hard upstream/main
git push origin main --force
This throws away everything on your main branch and resets to match upstream exactly. Everything. Make sure thatās what you want.
Cherry-Picking
If upstream has specific commits you want but you donāt need everything:
git fetch upstream
git log upstream/main --oneline # find the commit you want
git cherry-pick abc1234 # grab just that commit
Surgical precision. Take only what you need.
Contributing Back
Made something useful? Hereās how you give it back:
- Push your changes to your fork
- Go to the original repo on GitHub
- Click āNew pull requestā
- Click ācompare across forksā
- Select your fork and branch as the source
Write a good description, explain what you changed and why, and hit submit. Now you wait for the maintainers to review it.
Pro tip: smaller PRs get merged faster. Nobody wants to review 47 files.
The Mistake I See All The Time
Forking when you donāt need to.
If youāre on a team and you have write access to the repo, just clone it and make a branch. Forking adds a layer of complexity that serves no purpose when you already have access.
Fork = I donāt have push access, so I need my own copy.
Branch = I have push access, Iām just working on a feature.
Know the difference. Use the right tool.
Stay warm out there.
Happy automating!