No, the .git
directory does not have to be in your working directory. You can point a Git repository at another directory as its working directory using the --work-tree
option:
--work-tree=<path>
Set the path to the working tree. It can be an absolute path or a path relative to the current working directory. This can also be controlled by setting the GIT_WORK_TREE environment variable and the core.worktree configuration variable (see core.worktree in git-config(1) for a more detailed discussion).
Consider the following example:
$ # Create a Git repository
$ mkdir project
$ cd project
$ git init
Initialized empty Git repository in /path/to/project/.git/
$ ls -a
. .. .git
$ # Now, start working in another directory
$ cd ..
$ mkdir working-directory
$ cd working-directory
$ echo foo > foo.txt
$ # And now, commit to the initially created repository
$ cd ../project
$ git --work-tree=../working-directory status
$ git --work-tree=../working-directory add foo.txt
$ git --work-tree=../working-directory commi
It is very likely that Eclipse is using this option internally.