I have renamed my local Git repository folder through file system (Windows File Explorer) and now Git status (when inspecting repository through SourceTree) fails every time with
git status failed with code 128 this operation must be run in a work tree
Basically I only changed outside folder name, and I haven't touched inner repository structure.
OldRepoName
│ .gitattributes
│ .gitignore
│ README.md
│ │ ...
│
└───.git
│ │ config
│ │ ...
│
└─── ...
NewRepoName
│ .gitattributes
│ .gitignore
│ README.md
│ │ ...
│
└───.git
│ │ config
│ │ ...
│
└─── ...
All searches about "this operation must be run in a work tree" error I could find are dealing with bare repositories that never had work tree structure. This repository was not bare repository.
How do I fix the repo, without cloning it again from the remote?
Note: As a Mercurial user, I am quite used to renaming the repository folders, without any negative consequences.
Git repository contains configuration file which uses absolute path to the work tree. Fixing that path to point to new, renamed, folder fixes the repository.
.git/config
file in text editorworktree
entry under [core]
configurationfrom (this is Windows example, but same principle applies to other OS)
worktree = C:/OldPath/OldRepoName
to
worktree = C:/NewPath/NewRepoName