I've got a git repo in my home directory to keep track of some dotfiles.
An unpleasant side effect of that, no matter where I am now, it is considered a part of the ~
repo, and it's easy to mistakenly add files to it etc.
It is somehow possible, that the repo in ~/.git
listens to commands (git add
, etc) ONLY if these commands are invoked directly in ~
, and otherwise it just pretends to not exist, i.e. not a repository
is thrown? (For example, if I invoke git add -A
in ~/Documents
)
No this is not possible.
Another way, however, can be to use a non standard .git
directory :
.git/
directory to some other name (e.g : .git-wont-know/
, or .git-dotfiles/
)git --git-dir=~/.git-wont-know ...
when you want to interact with it (link to docs)You can set an alias or a wrapper to use this specific git dir ; you can also set GIT_DIR=~/.git-wont-know
if you want to pass this down to existing scripts.
[update] this turns off the "spot where the repo is located by looking for the .git
directory" feature.
If you want to invoke git with this setup from a subdirectory (say : from $HOME/.config/
), you may want to also specify that the worktree is your home directory :
git --git-dir=~/.git-wont-know --work-tree=~ ...
# or using environment variables :
GIT_DIR=~/.git-wont-know
GIT_WORK_TREE=~
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With