After finally getting around to turning my “Sloppy Joe” project into actual code, I spent a few hours here and there and worked out a simple React/Redux/Typescript project with a few hundred lines of code that had a pretty good start on the things I wanted it to do. It was time to push it up to GitHub.
I created the repo on GitHub, set my remote, and ran
git pullfrom my project directory.
To my horror, it replaced my local
masterwith the remote master, deleting everything that wasn’t specified by
.gitignore. I have
git pull --rebaseas my default setting, and the day finally came when that bit me hard. Knowing that any such problem has always been encountered by someone else, I searched around a bit on how to recover from a
git pull --rebasedisaster, and I found this little gem.
git reflog (Documentation)
This spits out raw commit references to everything you’ve been doing. From there, I was able to
git checkout [SHA], create a new branch
app-setup and merge my new
master up into that branch.
Since these two branches were effectively from two unrelated repos, it refused to merge these two branches and will give out the following error.
fatal: refusing to merge unrelated histories
And after some minimal-effort googling, I found that i just needed to
git merge [branch] --allow-unrelated-histories
I had to manually merge the README files, which was no big deal, since I intended to throw one out, and now everything is fine and my heart rate has returned to normal.