How I keep class repo forks sane
Published:
If you have ever forked a professor’s repo, pushed your own work, then pulled their new commits and hit a wall of merge conflicts, you are not alone. The fix is simple: wire your remotes correctly and rebase instead of merging.
Here is the clean setup I use:
- Fork the class repo on GitHub.
- Clone your fork locally. Git names it
originby default. - Add the professor’s repo as
upstream:
git remote add upstream https://github.com/professor/class-repo.git - Keep
originpointing to your fork:
git remote -vshould showorigin(your fork) andupstream(professor). - When the professor ships new commits, pull them with rebase:
git fetch upstream git rebase upstream/main - Resolve any small conflicts if they appear, then push your updated history to your fork:
git push --force-with-lease origin main
Why rebase instead of merge?
- Merge stacks a new merge commit that mixes your work and the professor’s work. That can tangle history and create conflicts in files you never touched.
- Rebase lifts your commits and places them on top of the professor’s latest commits. Your changes apply as if you started from their newest state, so you see conflicts only where both sides actually touched the same lines.
Mental model
Before rebase:
professor: A --- B
you: A --- B --- c --- d
After `git fetch upstream` + `git rebase upstream/main`:
professor: A --- B --- C --- D
you: c' --- d'
c' and d' are your commits replayed on top of the fresh base. That is why conflicts drop.
What I check before coding
- Remotes:
git remote -vshows origin (mine) and upstream (professor). - Branch: I am on
mainor a feature branch frommain. - Clean state:
git statusis clean before I pull.
Weekly habit
- Fetch and rebase from upstream before starting new work.
- Push with
--force-with-leaseonly after a rebase, to update your fork safely.
Do this, and the next time the professor pushes a surprise update, your fork stays calm instead of exploding with conflicts.
