setting the work-tree of each bare repo

后端 未结 3 1188
醉梦人生
醉梦人生 2020-12-29 12:54

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=/va         


        
相关标签:
3条回答
  • 2020-12-29 13:22

    Note that the proposed solution (2012, pre Git 2.5 which will be released in July 2015) would not work directly with git config command.
    It would keep dying with a:

    fatal: core.bare and core.worktree do not make sense.
    

    That is what Git 2.5 (July 2015) will address:

    See commit fada767 (29 May 2015) by Jeff King (peff).
    (Merged by Junio C Hamano -- gitster -- in commit 103b6f9, 16 Jun 2015)

    setup_git_directory: delay core.bare/core.worktree errors

    If both core.bare and core.worktree are set, we complain about the bogus config and die.
    Dying is good, because it avoids commands running and doing damage in a potentially incorrect setup.
    But dying there is bad, because it means that commands which do not even care about the work tree cannot run.
    This can make repairing the situation harder:

      [setup]
      $ git config core.bare true
      $ git config core.worktree /some/path
    
      [OK, expected.]
      $ git status
      fatal: core.bare and core.worktree do not make sense
    
      [Hrm...]
      $ git config --unset core.worktree
      fatal: core.bare and core.worktree do not make sense
    
      [Nope...]
      $ git config --edit
      fatal: core.bare and core.worktree do not make sense
    
      [Gaaah.]
      $ git help config
      fatal: core.bare and core.worktree do not make sense
    

    Instead, let's issue a warning about the bogus config when we notice it (i.e., for all commands), but only die when the command tries to use the work tree (by calling setup_work_tree).

    So we now get:

    $ git status
    warning: core.bare and core.worktree do not make sense
    fatal: unable to set up work tree using invalid config
    
    $ git config --unset core.worktree
    warning: core.bare and core.worktree do not make sense
    
    0 讨论(0)
  • 2020-12-29 13:22

    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.

    0 讨论(0)
  • 2020-12-29 13:37

    Bare repos are not supposed to have a work tree, so git prints the "fatal: core.bare and core.worktree do not make sense" error message. Therefore, you need to set bare = false in the repo's config file.

    user@host:~$ cd barerepo
    user@host:~/barerepo$ git config --bool core.bare false
    user@host:~/barerepo$ git config --path core.worktree /var/www/mywork
    

    However, if barerepo did not previously exist, you should use this command instead:

    git init --separate-git-dir=. /var/www/mywork
    

    This command will also create a .git file in the work tree pointing to the git dir:

    gitdir: /home/user/barerepo
    
    0 讨论(0)
提交回复
热议问题