setting the work-tree of each bare repo

Viewed 22498

As you can see below I have to set the work-tree of a bare repo:

cd barerepo
git status
fatal: This operation must be run in a work tree

git --work-tree=/var/www/mywork/ status
# On branch master
nothing to commit (working directory clean)

How do I set the work-tree for that repo so that I don't have to specify it everytime?

I tried modifying barerepo/config with this but it doesn't work.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
    worktree = /var/www/mywork
3 Answers

Note that the question and answers are from year 2012, but since git 2.5, even with a bare repository you can create separate worktrees with:

$ git worktree add /var/www/mywork/ master
$ git worktree add /var/www/workdev/ devel

See git-worktree(1).

It will not change core.worktree but create a worktrees directory in your git repository.

You may want to change the configuration option extensions.worktreeConfig to true if you don't want all the worktrees and the bare repository to share the same config.

Related