Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why some git commands are not allowed in the .git directory?

Tags:

git

There seems to be some inconsistency as to which commands are allowed when you are in the .git directory, and which are not. For instance

git symbolic-ref HEAD

or

git diff --staged

are fine.

But

git diff

or

git status

produces the error message: fatal: This operation must be run in a work tree

Even more surprising: create an alias of one of the failing commands above, like git st for git status, and then it works!

Is there any logical explanation for all that? And why would the alias of a failing command suddenly work just because it's an alias??

like image 642
Olivier Verdier Avatar asked Apr 02 '12 09:04

Olivier Verdier


1 Answers

There is a logical explanation. The commands with arguments that failed did so because they require a work tree and when you are in a .git repository there is no work tree, only repository files. The other commands with arguments succeeded because they do not require a work tree.

like image 123
GoZoner Avatar answered Oct 06 '22 06:10

GoZoner