March 13, 2026
3 likes
How I Merged a Total Rewrite
How I Merged a Total Rewrite
I took a somewhat unconventional and admittedly regrettable approach to this blog rewrite. Instead of branching from the existing source, I initialized a fresh Nuxt project in a completely new Git repository. When I attempted to set the upstream to a new branch on the original GitHub remote, I hit a wall: because the two branches shared no common history, I was met with this error during the merge:
fatal: refusing to merge unrelated histories
To Git, they were two entirely different projects that I was trying to smash together.
I wanted the new code, but I didn't want to lose the commit history on my main branch. Here's how I built the bridge between the two:
- I used the
--allow-unrelated-historiesflag to basically tell Git, "Yes, I know they aren't related. Merge them anyway."git merge -s ours nuxt-rewrite --allow-unrelated-histories
The-s ourspart is the key. It creates the history link without actually touching any files. - Once the "bridge" was built, I wiped the old files and pulled in the Nuxt files from the rewrite branch:
git rm -rf .git checkout origin/nuxt-rewrite -- . - I then committed the change and pushed. Now,
mainhas all the new Nuxt goodness, but if I scroll back in the commit log, the old history is still safely tucked away.
git reflog is a lifesaver. I had one small input error during the start of this merge and lost all of my changes. However, I then checked in and performed a hard reset to one of the commit hashes, resuming where I was.