Git checkout fails with detached worktree
[core] repositoryformatversion = 0 filemode = true bare = false worktree = /var/www/mysite.net/httpd/ # TO PUSH REPO TO STAGE: change bare=false and uncomment the worktree
Now though, I’m getting the error
fatal: This operation must be run in a work tree. I’ve got a bunch of sites set up this way so I’m sure I have just forgotten something, but I can’t figure out what. Can anyone think of what would cause this?
3 Solutions collect form web for “Git checkout fails with detached worktree”
Dumb mistake. That worktree should have been to a .com instead of a .net.
So I guess my answer is the usual one – double check your spelling.
Usually I use the git level options to get git to work like this:
git --work-tree=some/dir --git-dir=some/other/dir push
or, you can set the environment variables that have the same effect. In past versions of git, the effective active paths defined like this worked for some commands while not others.
Currently I’m using the git level options as they seem to work for all commands.
One more thing, if you override the work-tree, you need to also specify the git folder. Ie, you can’t specify one without the other.
If I am correct, the fundamental problem is that Git commands that are implemented by shell scripts do not work with a detached worktree by cd’ing to the repository directory. (Commands implemented by binaries do work in this situation.) To make script commands work with detached worktrees, cd to the work tree and use the GIT_DIR environment to tell Git where to look for the repository.