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

Re: git-dir requires work-tree; documentation improvements for working directory

From
YNYaroslav Nikitenko <metst13@gmail.com>
Date
Jan 3, 2021, 09:12 UTC
Message-ID
<CA+RLzGCfqNdup1cmz3W4iBzbsxe9SD7E+Ju4svNFvhe6ohJqjA@mail.gmail.com>
In-Reply-To
<5ff0ed59489bd_a76d2082f@natae.notmuch>
2021-01-03 1:02 GMT+03:00, Felipe Contreras <felipe.contreras@gmail.com>:
Show 31 quoted lines
> Yaroslav Nikitenko wrote:
>> 2021-01-02 22:12 GMT+03:00, Felipe Contreras
>> <felipe.contreras@gmail.com>:
>> > Yaroslav Nikitenko wrote:
>> >> I use git to manage my dotfiles with this command:
>> >>
>> >>     git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav
>> >
>> > I do precisely the same thing.
>> >
>> >> When reading documentation, I noticed two issues.
>> >>
>> >> 1) The command doesn't work without --work-tree (even from the top
>> >> level directory, which is my home directory).
>> >>
>> >>     [~]$ git --git-dir=/home/yaroslav/.cfg/ status
>> >>     fatal: this operation must be run in a work tree
>> >
>> > That's weird. It works fine here (although I don't see why I would want
>> > that).
>>
>> BTW, how do you do that in your case?
>
> I have an alias:
>
>   alias config='git --git-dir=$HOME/.config/dotfiles/.git/
> --work-tree=$HOME'
>
> So, when I'm in my $HOME, I can do:
>
>   config status
Thanks.
Show 26 quoted lines
>> > If you remove all your configuration does it still fail?
>>
>> It starts to work when I remove my .cfg/config. I've no idea why it
>> happens. Here is its contents:
>>
>> $ more .cfg/config
>> [core]
>> 	repositoryformatversion = 0
>> 	filemode = true
>> 	bare = true
>
> That's the difference: my core.bare is false.
>
> I do have a checked out work-tree because that's the only way I could
> get some commands to work, for example `git rebase`, even though I don't
> use that work-tree.
>
> I'm not sure if it makes sense to not assume '.' is the work-tree when
> 'core.bare=true', but I think it does make sense, so maybe just turn
> that off.
>
> Cheers.
>
> --
> Felipe Contreras
>

Thanks for the suggestion. I'd rather not change my config at the moment. It's not difficult to provide work-tree in the alias.

However, I think that this is a bug in the implementation or the documentation. It's not highlighted anywhere that the repository must be non-bare for git-dir to work without explicit work-tree (an opposite is stated in general).

Should I write a letter with [BUG] in its header for that to be noticed? I'm surprised why there is no issue tracker for git.

Cheers, Yaroslav Nikitenko

Previous: Felipe ContrerasNext: Felipe Contreras
Message 5 of 7 in “git-dir requires work-tree; documentation improvements for working directory”
  1. Yaroslav NikitenkoJan 2, 2021
  2. Felipe ContrerasJan 2, 2021
  3. Yaroslav NikitenkoJan 2, 2021
  4. Felipe ContrerasJan 2, 2021
  5. Yaroslav NikitenkoJan 3, 2021
  6. Felipe ContrerasJan 3, 2021
  7. Junio C HamanoJan 4, 2021

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.