Git checkout fails with detached worktree

I have a repository with a detached worktree. Normally if I need to work on the repo, I can change the config file as follows and use commands like git status and git checkout:

        repositoryformatversion = 0
        filemode = true
        bare = false
        worktree = /var/www/

#       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?

  • Git: Only push private config file to test repository and not to github?
  • Why does git difftool use git diff instead?
  • How can you git pull only the current branch?
  • What is git's “filemode”?
  • How to set a Git config option when its config file is “$XDG_CONFIG_HOME/git/config”?
  • Cordova install platforms/plugins from config.xml
  • Giving priority to GIT in GIT/SVN mixed project in Netbeans?
  • Powershell/PoshGit - 'Could not find ssh-agent'
  • Git BFG to retroactively enable LFS - protected commits issue
  • `git:remote` is not a heroku command
  • How to setup Continuous Integration in Visual Studio Online with Git and Nunit
  • Installing Git on Eclipse
  • 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.

    Git Baby is a git and github fan, let's start git clone.