Environment
Setup
I use a git bare repository to version my config files. I can use same commands as if I were using a normal git repository just have to include some flags:
git --git-dir=/home/kunzaatko/.cfg/ --work-tree=/home/kunzaatko/ __command__
instead of
git __command__
Usage
I make use of vim-fugitive with normal git repositories mainly for making a big change and adding it in many different commits by staging partially (only a discrete set of hunks/changes) and committing them separately . I use :Gdiff
for this for the nice and productive interface I can make use of.
Desire
I want to do this with my config git bare repository.
What I tried:
Renaming the repository to
.cfg.git
. This didn't make any change. issue that suggests this should workI tried to change the
b:git_dir
internal variable of git-fugitive:
:let b:git_dir=/home/kunzaatko/.cfg/
- Changing the working directory to the git directory for fugitive to recognize that it is a git repo:
:chdir /home/kunzaatko/.cfg/
What would be worthy of trying if I knew how:
- I think that there may be a way to use the
git submodule
command to put the bare repo into scope. The problem with that is where to put the root of the git repository... issue that I base this possibility of of
Question
Is there a way to use a git bare repository with git-fugitive?
(or any other suggestion that would solve my use-case)
I agree with @okket, but there is a problem when I use that method.
When in Gstatus window, I cannot get the status of changed files. And I find the reason is that fugitive gets the
core.worktree
attribute from theGIT_DIR
repository.So for me, the viable way to do this is as follows:
GIT_DIR
env variable when using vim/nvim command (GIT_WORK_TREE
may be omitted):For users of fish shell (like me), should use
env
command:core.worktree
for your git repository:You can make sure you get it right with the following command:
The output should be your HOME path.
git clone --bare ...
, you need to unsetcore.bare
to avoid git status errorwarning: core.bare and core.worktree do not make sense
:And there is one more thing to notice for this method. You cannot use fugitive outside of
$HOME
directory where you will getfugitive: working directory does not belong to a Git repository
error.