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

Re: describe with --git-dir and --dirty outside of the repo always says dirty

From
Thomas Braun <thomas.braun@virtuell-zuhause.de>
Date
Mar 18, 2026, 17:33 UTC
Message-ID
<9cb575c2-a08a-429d-a7d2-cdceda8389bf@virtuell-zuhause.de>
In-Reply-To
<abe9uDp16zOcdzZs@pks.im>
Am 16.03.2026 um 09:22 schrieb Patrick Steinhardt:
Show 38 quoted lines
> On Fri, Mar 13, 2026 at 01:29:29PM -0700, Junio C Hamano wrote:
>> Thomas Braun <thomas.braun@virtuell-zuhause.de> writes:
>>
>>> When I do
>>>
>>> git describe --dirty
>>>
>>> in clean repo of git.git I get
>>>
>>> v2.53.0-522-g67006b9db8
>>>
>>> but when I do it from outside of the repo
>>>
>>> cd ..
>>> git --git-dir=git/.git describe --dirty
>> "--git-dir" tells git "I am at the root of the working tree, but the
>> git directory that you usually find at ".git" (or a parent directory
>> of where we are) is not where you expect but somewhere else, so I am
>> telling you where it is with this argument.
>>
>> So if you are not at the root of the working tree for that working
>> tree, "git --git-dir=git/.git diff" would report that you have a ton
>> of changes to working tree files, and "describe" would report that
>> your working tree is dirty.
>>
>> In other words, working as intended.
>>
>> You can tell where the working tree is (instead of telling the
>> command that you are at the root of the working tree, when you are
>> not), with the "--work-tree" option.
>>
>> $ git --git-dir=git/.git --work-tree=git describe --dirty
> You can do that, but what you're probably looking for is `-C`:
>
>      $ git -C /path/to/git describe --dirty
>
> As Junio pointed out, "--git-dir" has a different effect, and you
> typically don't have to use it unless you're doing weird stuff.

Thanks both Junio and Patrick. The documentation is not lacking and fully explains that -C is the way to go. I should have checked first.

My lameish excuse for originally using --git-dir is that -C which was added in 44e1e4d67d (git: run in a directory given with -C option, 2013-09-09) was too new back then I added the code originally in 2014.

Thomas
Previous: Patrick Steinhardt
Message 4 of 4 in “describe with --git-dir and --dirty outside of the repo always says dirty”
  1. Thomas BraunMar 13, 2026
  2. Junio C HamanoMar 13, 2026
  3. Patrick SteinhardtMar 16, 2026
  4. Thomas BraunMar 18, 2026

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.