Learn you an interactive rebase and other fancy git stuff - part 2
In yesterday's installment we
git spike alias to quickly checkout a copy of our branch. We also
want a quick way to delete these spike branches, as we'll be making a lot of
mistakes, lets add an alias to do that.
# ~/.gitconfig [alias] cb = rev-parse --abbrev-ref HEAD spike = "!git checkout -b $(git cb)-spike" dspike = "!git branch -d $(git cb)-spike" Dspike = "!git branch -D $(git cb)-spike"
Now we can remove our spikes by checking out our previous branch
git checkout -
git dspike or
git Dspike if we've committed changes and want to
force deleting the branch.
The last alias I want to cover is
git tree-state. It returns a hash of the
files committed to git. If any file changes you get a different hash. This is
a good sanity check to make sure you end up in the same state when messing
around with git history.
# ~/.gitconfig [alias] cb = rev-parse --abbrev-ref HEAD spike = "!git checkout -b $(git cb)-spike" dspike = "!git branch -d $(git cb)-spike" Dspike = "!git branch -D $(git cb)-spike" tree-state = "!git log --pretty --format='%t' | head -n1"
Given a branch with a bunch of commits you want to clean up, my learning git rebasing workflow is.
git tree-state- get the current state of files known to git.
git spike- checkout a copy of the branch to experiment on.
- Do the rebase or whatever gnarly thing you want to try.
git tree-statemake sure we end up with our files in the same state as when we started.
git checkout -to get back to our 'real' branch.
- Redo all the git wizardry, now we know what we need to do, on the main branch.
git Dspiketo remove our spike branch.
Step 6 is a bit redundant, but I recommend repeating the rebasing as
practice. If you don't want to redo the whole rebase you can use
git branch --move to rename your spike branch and make that the new
That's today's 200 words covered.