Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout fails with detached worktree

Tags:

git

config

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:

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

like image 712
doub1ejack Avatar asked Mar 23 '26 01:03

doub1ejack


2 Answers

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.

like image 111
doub1ejack Avatar answered Mar 24 '26 15:03

doub1ejack


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.

like image 27
Adam Dymitruk Avatar answered Mar 24 '26 15:03

Adam Dymitruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!