git fixup -- your workflow

Photo by Yancy Min on Unsplash

git fixup -- your workflow

Fix your rebase workflow

"Woah!" this was my reaction when I discovered the --fixup flag for git commit command. It reduces the time spent on working on features/fixes by:

  1. Avoiding temporary commit messages.

  2. Eliminating the time taken to remove the temporary commit messages.

  3. Helping with organized rebases.

  4. Helping with quicker squashing of commits.

Let me walk you through the old workflow that I used to employ when I worked on any feature/fixes. I generally start with a fresh branch from the main branch.

git checkout -b farhaan/great-looking-feature

Then I will keep working on the branch and keep adding the commits. The commits are a result of a review or some additional fixes. Once the review is completed I need to squash the commits. The difficulties I face here are:

  1. If I have done multiple fixes by any chance I will not be able to segregate them.

  2. I need to count the number of commits to pass it to HEAD~<number> for interactive rebase.

Hence, when my work on the feature branch is done I would have to first squash my commits and then rebase the branch over main. Suppose I have 5 commits to squash I will have to run:

git rebase -i HEAD~5

There will be an editor window that will open and we need to select the commit to squash or to pick. Then there will be an editor window to modify the commit message if you want to.

All the above problems and steps are easily fixed and simplified by the --fix-up workflow. Here I put all the effort that I need into writing my first commit messages then later messages are prefixed by fixup. I can even segregate my changes into multiple commit messages. Let me show an example:

To add a fixup commit I need to give the commit hash that I want to fixup.

git commit --fixup=632aa92e0d27332b4d7caf70eb268a23d3544610

This adds the commit message fixup! First commit [feat]. Now, if we want to squash the commit message we need to autosquash .

git rebase -i --autosquash e05a9e0

We just need to be sure to give the commit hash till we want to squash.

And the result is *Drum Rolls*

I hope this workflow will help you save a lot of time and improve the way you use git. Happy Hacking!

Did you find this article valuable?

Support Farhaan Bukhsh by becoming a sponsor. Any amount is appreciated!