git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Command whose exit code indicates clean or dirty working directory

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 10, 2025, 22:11 UTC
Message-ID
<Z_hB9gZL6FE7PezC@tapette.crustytoothpaste.net>
In-Reply-To
<jreR52go49E9pIfAmIdRaoqIgKnVV7uOhR4Mbl9_p2dLG_7mPgO8qsUk7CaWC0nGbJD-2F4nGdQ8X65UtIQ5XOBNQXXzrnHnKbOCLCfEil0=@proton.me>
On 2025-04-10 at 17:49:23, Ross Goldberg wrote:
> What is the simplest git command that returns 0 if the working directory is completely clean, or nonzero if it is dirty in any way (staged diff, unstaged diff, file that is both untracked &amp; not ignored, etc.), with nothing printed to stdout or to stderr?
> If the simplest such command is complex, is there any feature request to create a simple command, possibly with options that specify what is considered dirty (staged diffs, unstaged diffs, untracked &amp; not ignored, etc.)?
Here's what I've used:
[ -z "$(git status --porcelain)" ]
That assumes you know the directory is a non-bare working tree.

`git status --porcelain` prints nothing if the working directory is clean and prints what's dirty otherwise.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Previous: Junio C Hamano
Message 3 of 3 in “Command whose exit code indicates clean or dirty working directory”
  1. Ross GoldbergApr 10, 2025
  2. Junio C HamanoApr 10, 2025
  3. brian m. carlsonApr 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.