---
title: "Strip Trailing Whitespace from Git projects"
description: "A common linting error thrown by various linters is for trailing whitespace. I most often use flake8. I generally have pre-commit hooks setup to strip this,..."
date: 2020-09-30
published: true
tags:
  - git
  - pre-commit
  - python
template: blog-post
---


A common linting error thrown by various linters is for trailing whitespace.  I
most often use flake8.  I generally have
[pre-commit]([https://waylonwalker.com/pre-commit-is-awesome](https://waylonwalker.com/pre-commit-is-awesome/)
hooks setup to strip this,
but sometimes I run into situations where I jump into a project without it, and
my editor lights up with errors.  A simple fix is to run this one-liner.

## One-Liner to strip whitespace

_<small><mark>bash</mark></small>_
``` bash
git grep -I --name-only -z -e '' | xargs -0 sed -i -e 's/[ \t]\+\(\r\?\)$/\1/'
```



<p style='text-align: center' align='center'>
<a href='https://waylonwalker.com/pre-commit-is-awesome'>
  <img
    style='width:400px; max-width:80%; margin: auto;'
    width='400'
    src="https://images.waylonwalker.com/pre-commit-is-awesome.png"
    alt="pre-commit article"
  />
  </a>
</p>

read more about how  <a href="/pre-commit-is-awesome/" class="wikilink" data-title="pre-commit is awesome" data-description="I recently discovered the ✨ awesomeness that is pre-commit. I steered away from it for so long because it seemed like a big daunting thing to set up, but..." data-date="2020-06-05">pre-commit is awesome</a>
