. Advertisement .
..3..
. Advertisement .
..4..
Git was just set up on Windows. I’m tired of fixing this error ”fatal: this operation must be run in a work tree” when I set the GIT_DIR variable to be c:\git\ and verified that this environment variable is maintained by cygwin (i.e. echo $GIT_DIR is what it should be). I went to the folder which I wanted to create the git repository for, let’s say c:\www, and then ran:
git init
git add .
Then I get this error message:
fatal: This operation must be run in a work tree
I don’t know what went wrong, but the c:\git directory has a config file that says:
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
I don’t have any experience with the “fatal: this operation must be run in a work tree” error. In this case, how should I change?
The cause: I think this error happens because it can’t use
git-add
with a bare repository. By definition, a bare repository lacks a work tree. In order to prepare for committing, git-add adds files from the work tree to the index.Solution: To solve this problem, you need to set
GIT_WORK_TREE
to a path including everything you wish to track., and then to block out everything you aren’t interested in tracking, you will needa.gitignore
because GIT_DIR is the repository directory used for all git commands and by definition, a git repository tracks the contents of a single directory.Perhaps you’re attempting to build a repository that only tracks
c:www
? If you don’t want to set GIT DIR, you should place it inc:www
. This is how git is often used, with the repository located in the .git directory of the “module’s” top-level directory.I would advise sticking with how git like to work unless you have a really compelling reason not to. You may want numerous repositories if you have a lot of stuff to track.