简体   繁体   中英

GIT not finding the .git directory when in the top-level of a project

I am working in a Windows Server 2008 environment and trying to use git. I have found that if I create a directory and then run the git init command inside that new directory, it will create the regular directory structure (a .git folder). If I then type git status from that same directory I get the following error:

fatal: Not a git repository (or any of the parent directories): .git

If I then create a directory under that top-level project directory and move into it, the git status command works. When I transition back to the top-level project directory, the git status command fails again with the same error. If I explicitly set the environment variable GIT_DIR to the full path of the project directory, I can then execute git status and things work.

I cannot rely on manually setting the GIT_DIR every time I switch to a different project because I am forced to use GUI tools. Regardless of that, I have never needed to specify the GIT_DIR environment variable for git to work correctly.

Can somebody help me understand what might be going on here so I can fix it so git works cleanly?

On MacOS I can say that your error does not occur.

That said, with a new git repo, it's kind of in a weird state until you do your first commit. In my test, until the first commit 'git branch' shows nothing, even after adding an empty file. After the first 'git commit' then the branch exists. It might be on Windows there's other weirdness going on that all magically resolves itself once you do the first commit and the master branch exists.

On MacOS, you can't do a 'git branch' because there's no master branch (or anything else) to base it upon, so again gotta have something to branch, which is the branch created with your initial 'git commit'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM