fatal: This operation must be run in a work tree [duplicate]

I get this error when I try to change branch.

Probably I will give some information of the commands at

/path/to/git/repo/. 

upon command:

git branch 

I get following output

* V1.5 V2.0 master 

And when I try the command

git checkout V2.0 

I get following output:

fatal: This operation must be run in a work tree 

config file contents:

cat config [core] repositoryformatversion = 0 filemode = true bare = true [remote "origin"] url = /path/to/git/repo/.git 
1

1 Answer

You repository is bare, i.e. it does not have a working tree attached to it. You can clone it locally to create a working tree for it, or you could use one of several other options to tell Git where the working tree is, e.g. the --work-tree option for single commands, or the GIT_WORK_TREE environment variable. There is also the core.worktree configuration option but it will not work in a bare repository (check the man page for what it does).

# git --work-tree=/path/to/work/tree checkout master # GIT_WORK_TREE=/path/to/work/tree git status 
16

You Might Also Like