Lightning Fast Git Commit Cleanup with git-absorb: Automating ‘fixup’ over Manual Rebase

Git tutorial - IT technology blog
Git tutorial - IT technology blog

Getting started with git-absorb in 5 minutes

Working on real-world projects, you’re likely familiar with using git rebase -i to squash minor commits like “fix typo” or “update logic” into the main commit. The traditional workflow is often clunky: find the commit hash, type git commit --fixup <hash>, then autosquash. Just copy-pasting the hash is exhausting enough.

git-absorb is the solution that lets you skip those manual steps. Instead of making you search for them, it automatically matches your recent changes against the commit history. It then “absorbs” the code into the original commit that generated those lines.

Quick Usage:

  1. Modify your code to fix a bug or add changes.
  2. Stage the files using git add ..
  3. Type git absorb.
  4. Run git rebase -i --autosquash @{u} to finalize the cleanup.
# Real-world example: handled in 10 seconds
$ git add src/services/auth.py
$ git absorb
# The tool will automatically find the old commit and create a fixup commit instantly
$ git rebase -i --autosquash @{u}

Why should you use git-absorb instead of the traditional way?

Imagine a Senior developer spots a small bug in your first commit, while your Pull Request (PR) has already stacked 10-15 different commits. Digging through history to find which commit a specific line belongs to is extremely time-consuming and error-prone.

Essentially, git-absorb works intelligently using a mechanism similar to git blame. It scans every line you’ve staged in the index, determining which commit in the HEAD..@{u} range last modified that line. If it identifies a single safe target commit, it automatically creates a corresponding fixup! commit.

Valuable Benefits:

  • Boost Productivity: Saves about 2-3 minutes per PR cleanup compared to manual hashing.
  • Absolute Accuracy: Eliminates the risk of fixing up the wrong commit, which often leads to messy rebase conflicts.
  • Impress Reviewers: Keeps your commit history crystal clear before submission. Reviewers will find it much easier to read distinct commits rather than a pile of “fix typo” junk.

Installing git-absorb

This tool is written in Rust, making it extremely lightweight and fast. You can install it via cargo or popular package managers.

On macOS:

brew install git-absorb

On Linux (Ubuntu/Debian):

sudo apt install git-absorb
# Or use cargo if not available in your distro
cargo install git-absorb

On Windows:

After installing Rust and Cargo, simply run:

cargo install git-absorb

Real-world Workflow

I use this combo daily to keep my PRs polished. Suppose you’re working on a Login feature with 3 commits: 1. Init Database, 2. Add Auth Service, 3. Update UI.

Suddenly, you notice the variable user_token in commit #1 is misnamed. Instead of creating a new “fix: rename variable” commit, do this:

  1. Fix the variable name in your code.
  2. Run git add ..
  3. Type git absorb. The tool understands this change belongs to the “Init Database” commit and immediately creates a fixup commit at the top.
  4. Finally, run git rebase -i --autosquash @{u}. Everything is pre-arranged; you just need to save and exit.

Note: git-absorb only sees what you have staged with git add. If you forget to stage files, it will report that there is nothing to process.

Hard-won Lesson: Don’t let Force Push hurt you

After using git-absorb and rebasing, you must force push because the history has changed. To stay safe, always use git push --force-with-lease instead of --force.

This command checks if a colleague has pushed new code to that branch while you were rebasing. If they have, it blocks the push to prevent overwriting someone else’s work. A small habit that saves you from many “embarrassing” moments with the team.

Personally, I find this tool incredibly useful when I’m in a “coding flow.” If I spot a bug elsewhere while working on something, I just fix it quickly, git add, git absorb, and I’m done. Your mind is free to return to the main logic without interruption.

Advanced Tips for Pros

1. Set up Aliases to type faster

To optimize speed, add these aliases to your .gitconfig file:

[alias]
    ab = absorb
    ri = rebase -i --autosquash

Now, the ultimate cleanup combo is just git ab and git ri @{u}. Incredible speed!

2. Limit the scan range

By default, the tool scans back 10 commits. If you need to search further, specify a base:

git absorb --base <commit-hash>

3. When does git-absorb give up?

It’s not magic. If a line of code you modified is contested by too many different commits, the tool will report a “multi-candidate” error. This is rare if you keep commits small, but if it happens, you’ll have to resort to manual rebasing.

Summary

Using git-absorb is a way to upgrade your workflow: focus entirely on the code and let the tool handle the tedious Git procedures. For Juniors, mastering these small but powerful tools will make you look much more professional in the eyes of Seniors.

Try installing and using it for your current project—I guarantee you’ll never want to go back to manual rebasing!

Share: