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 git@github.com:YOUR-USERNAME/repo-name.git
cd repo-name
# 3. Add the original as "upstream" so you can pull their updates
git remote add upstream git@github.com:ORIGINAL-OWNER/repo-name.git
# 4. Verify you've got both remotes
git remote -v
# origin git@github.com:YOUR-USERNAME/repo-name.git (fetch)
# origin git@github.com:YOUR-USERNAME/repo-name.git (push)
# upstream git@github.com:ORIGINAL-OWNER/repo-name.git (fetch)
# upstream git@github.com: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!