0

When I type git status in any folder it lists the status of one of my git projects, compared to the current folder. Even when I am in another git project. Also, if I cd to /root folder and check there is no .git folder present and type in git status I will see the status of that folder against my git project.

Is there some default mapping in git, global config looks ok?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Patrick Clancey
  • 1,330
  • 1
  • 14
  • 22

2 Answers2

2

When you have GIT_DIR set in the environment, but not also GIT_WORK_TREE, then you are operating Git outside its specifications. Either:

  • Remove GIT_DIR from the environment and let Git discover the .git directory itself,

  • Or set GIT_WORK_TREE as well to point to the worktree corresponding to the GIT_DIR.

But, frankly, the latter is really not how one wants to operate Git during regular work. You should do the former.

j6t
  • 9,150
  • 1
  • 15
  • 35
1

Well... it's in the comments, but for visibility:

This happens if you have a GIT_DIR environment variable pointing to a particular repository. GIT_DIR overrides the normal directory-search rules for finding the .git folder and simply says "you're in a repo and the metadata is here".

Generally I would clear the GET_DIR variable, and only set it when needed. I'm not sure what purpose you have it set for, and to the extent that purpose is still a thing, you may have to do some other stuff first to make sure it's set when it should be. But I can say the only times I've ever used GET_DIR are in scripts (and then I make sure to clear it when the script's work is done) and I can't think of why you'd want it set all the time - for the reason you've just experienced.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52