# git fixup -- your 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.

```bash
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:

```bash
git rebase -i HEAD~5
```

There will be an editor window that will open and we need to select the commit to `s`quash or to `p`ick. 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:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700653349115/b0f34343-f964-45f1-9a56-6e5ec8f9b684.png align="center")

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

```bash
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` .

```bash
git rebase -i --autosquash e05a9e0
```

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700653679847/fd5e8b50-1583-4048-af77-e23c1640eb42.png align="center")

And the result is \*Drum Rolls\*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700653756023/04baad8f-a02f-4703-84fa-bb7ea329c778.png align="center")

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