Git made me resolve 47 commits worth of conflicts. Here's what happened.
Friday afternoon. Pushed some code to GitHub, opened a PR, feeling good about myself. Client wanted to see a demo Monday morning.
Monday I open the repo, switch to main, pull latest.
47 commits behind.
Cool cool cool.
So here's the setup. Multiple devs, feature branches, normal stuff. I was working on auth-redesign for about a week. Made changes, pushed, opened PR.
Except the PR had conflicts. I thought "no big deal, fix them after the demo, code works fine for what client needs."
This was a mistake.
I let the branch drift for three days. Just kept making commits while the team kept merging to main. Didn't touch main once during that time.
Monday morning my local main and the actual main were basically different universes. Someone had force-pushed while I was gone. When I tried to merge my feature back in, git saw 47 commits worth of differences.
I had two options.
Option A was to merge main into my branch, resolve conflicts, then merge back. This works but gives you ugly merge commits everywhere. Your git log looks like spaghetti.
Option B was to rebase:
git fetch origin
git checkout main
git reset --hard origin/main
git checkout auth-redesign
git rebase main
This replays my commits on top of current main. Clean history.
But rebase replays each commit one by one. And if any of those commits conflict with the new base, you resolve manually. For each one. Commit 1, resolve, commit 2, resolve, commit 3, resolve.
I had 47 commits. Some of them conflicted. Some of the same files conflicted across multiple commits because I had made similar changes in consecutive commits.
By commit 30 I was fixing the same three files over and over.
2 hours. Not exaggerating. 2 hours of git conflict resolution. At one point I had five files open with conflict markers and I couldn't remember what the original code was supposed to do.
The problem wasn't git. It was that I let my branch drift.
When you don't sync with main for days, the gap grows. A rebase that could be 3 commits becomes 20 becomes 47 because you kept making small commits without pulling in the latest changes.
Now every morning before I start anything:
git fetch origin
git rebase origin/main
Even when I'm not ready to merge. Even when I'm deep in feature work. Keeps everything current so when I am ready, it's a couple commits instead of 47.
Sounds simple. Would have saved me 2 hours.
Top comments (0)