Search code examples
gitgithuberror-handlingversiongit-gui

Git Error In Windows - fatal: This operation must be performed in a working tree


I have a problem with Git, I get the following error when I run the command git init : Reinitialise existing Git repository in C:/Users/Documents/Projects/.

But if I also give the command git add . I get the following error: fatal: This operation must be performed in a working tree. Finally, when I try to enter git-gui I get the following message

fatal: This operation must be performed in a working tree while executing "clse $fd" (procedure "git" line 5) called from within "git rev-parse --show-toplevel" (file "C:/Program Files/Git/mingw64/libexec/git-core/git-gui.tcl" line 1297) called from the "source [file join [file dirname[info script]] git-gui.tcl" line (file "C:\Program Files\Git\mingw64\libexec\git-core\git-gui" line 25).

I have already tried everything, from deleting the data from my pc, deleting the git folder, manually creating the git folder, etc.

I would like to receive help on what to do to solve this problem.


Solution

  • I think you have the problem with GIT_WORK_TREE and GIT_DIR system variables.

    I got the same problem but I have solved it when I removed these GIT_WORK_TREE and GIT_DIR variables from system variables.

    • Check if you have these system variables GIT_WORK_TREE and GIT_DIR in your system variables.
    • try to delete these variables and reinitialize the repo this will solve the problem.