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?

  • Adding ALIAS to GIT config for a set of commands
  • Branching: different config files for release/development
  • Is storing FTP credentials in git-ftp settings in repository insecure?
  • How to programmatically configure a Git branch's description?
  • How can I commit/push a git alias (in .git/config)?
  • Open sourcing code without including specific set-up values in source
  • Migrating from Bamboo
  • Switching Git branches inside an Android Repo project
  • How to detect whether a given remote repository is a Git repo or SVN repo?
  • Show all commits whose diff contain specific string
  • Combine few commits. Git rebase
  • Working on a pull request, while updating master
  • 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.