Skip to content

Instantly share code, notes, and snippets.

@nathabonfim59
Created October 7, 2025 23:03
Show Gist options
  • Select an option

  • Save nathabonfim59/a0f5bfcd01b042f630b4704daf2c3476 to your computer and use it in GitHub Desktop.

Select an option

Save nathabonfim59/a0f5bfcd01b042f630b4704daf2c3476 to your computer and use it in GitHub Desktop.

How to get rid of random empty spaces in your commits

If you use LLM coding agents, I'm sure you dealt with random empty spaces in your codebase

The solution is simple: add a pre-commit hook to your project

No custom rules to spend your tokens, no extra steps necessary. Just set and forget

Instructions

  1. Navigate to your project. Keep in mind it needs to be a git repo.
  2. Open the folder .git/hooks
  3. Create a file named pre-commit
  4. Paste the code below
#!/bin/bash

# Remove trailing whitespace from staged files
for file in $(git diff --cached --name-only --diff-filter=ACM); do
    if [ -f "$file" ]; then
        sed -i 's/[[:space:]]*$//' "$file"
        git add "$file"
    fi
done

exit 0
  1. Set the permissions by running the following command in your terminal (same folder as your git repo).
chmod +x .git/hooks/pre-commit

DONE! From now on, git will automatically get rid of it for you at every commit.

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment