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__
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.
I want to do this with my config git bare repository.
Renaming the repository to .cfg.git
. This didn't make any change. issue that suggests this should work
I tried to change the b:git_dir
internal variable of git-fugitive:
:let b:git_dir=/home/kunzaatko/.cfg/
:chdir /home/kunzaatko/.cfg/
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 ofIs 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 the GIT_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):GIT_DIR=$HOME/.cfg GIT_WORK_TREE=$HOME [n]vim
For users of fish shell (like me), should use env
command:
env GIT_DIR=$HOME/.cfg GIT_WORK_TREE=$HOME [n]vim
core.worktree
for your git repository:git --git-dir=$HOME/.cfg --work-tree=$HOME config --local core.worktree $HOME
You can make sure you get it right with the following command:
git --git-dir=$HOME/.cfg --work-tree=$HOME config --local core.worktree
The output should be your HOME path.
git clone --bare ...
, you need to unset core.bare
to avoid git status error warning: core.bare and core.worktree do not make sense
:git --git-dir=$HOME/.cfg --work-tree=$HOME config --unset core.bare
And there is one more thing to notice for this method. You cannot use fugitive outside of $HOME
directory where you will get fugitive: working directory does not belong to a Git repository
error.
PS: I'd like to comment on @okket 's answer, but due to low reputation I can only post a new answer here.