git with –git-dir= results in ‘not a git repository’

When using --git-dir, you need to point at the .git folder of your repository. Try:

git --git-dir=projectDirPath/.git show -s --pretty=format:%h

The doc on --git-dir says that:

–git-dir=

Set the path to the repository (“.git” directory). This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

I use to have an issue remembering this myself. To help me remember what to do, I try to remember that the option is asking for exactly what it wants: the path to the .git directory (git-dir).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)