Search code examples
eclipsegitgit-bashegit

Git init always initializing a repository in the same folder


I try to init a new Git local repository using either Git Bash or Egit in Eclipse. It always creates it in some default directory rather than current working directory (or specified path in case of Egit). EGit after trying to clone a repo returns an error that specified folder "does not look like git repo" - because it failed to init it correctly. Whatever I do, git init always produces files in the same place. Any idea?


Solution

  • I managed to find the reason. Git (and Egit which is also respecting environment vars) is using the path specified in GIT_DIR environment variable and completely ignoring current working directory. I once specified GIT_DIR in windows env vars, but then deleted it and it was not on the list anymore. Somehow, when I echoed it in Git Bash it was still there. Adding it again in windows vars and deleting again did the job.

    Here I should note two bugs I discovered:

    1. Windows is not always deleting environments vars and the may stay there with the old values (probably difficult to reproduce as it does not occur always).
    2. EGit is respecting the GIT_DIR variable but still asking for the repo directory. This produces an error because the .git folder is in completely different location that Egit is looking for.