I'm trying to have a good Git workflow for contributing to an open source project (Endless Sky), but learning as I started out I've not ended up with a clean history. My workflow now is:
upstream/master
is here.- My fork is here. I started using GitHub Desktop, but am beginning to switch to the command line.
- My fork's master is supposed to mirror the
upstream/master
. Each feature I develop has a branch to itself, created from my master, and I use my own (local)alpha
and (pushed)beta
branches for combining my features to test/play.
My problem is on my forked master: This branch is 15 commits ahead of endless-sky:master.
No files changed; it's merge commit messages. This seemed ugly to me, so I did some reading, particularly the article Stop using 'git pull': A better workflow, and I've switched to rebasing/fast-forwarding.
But what's the best way to clean up an existing merge commit history in this situation? It touches a few of my feature branches too (see: feature/JammingHaywire
), and I don't want to be submitting a PR where the meaningful commits are drowned by meaningless merge commits.
I've read various other questions and am not quite clear whether I'm best:
- deleting/remaking
master
— is that safe, particularly with GitHub? - trying to do a
git rebase -i [which commit?]
back to some point — doesn't seem to work. Tried it back to0facf00
, some commit long before I forked, and my merge commit hashes (e.g.3be4d97
seen on GitHub) don't show up in the text file to drop. The end result is unchanged. - doing something else I haven't thought of yet? Is what I'm trying to do 'good practice' in the first place?
Your first option, deleting and recreating
master
, is probably the easiest. Here's how you can clean things up:If you haven't already, switch to
master
:Create a backup branch, just in case:
Reset
master
to match that ofupstream
. This is effectively the same as deleting and recreating the branch, your option 1, but only requires one command:Force-push:
Obligatory warning: Since a rebase rewrites history, this can be dangerous / disruptive for anyone else working on this branch. Be sure you clearly communicate what you have done with anyone you are collaborating with. Since this is a personal fork, I assume this won't be an issue for you.
Your
master
branch is now up to date withupstream/master
, so on GitHub you should see:If you find later that you are missing anything, you can look through the history of
backup
to find it.To fix any feature branches that were similarly mangled, do:
Your editor will open and you will see a list of commits. Delete any lines containing the extra merges, then save and exit. Again push with
--force-with-lease
.