How can I make git commands (e.g. git status) not operate on a repository if my working directory is ignored by that repository? For example:
I run
git initin ~ to create a repo to track dotfilesI add a
.gitignorefile in ~, which looks like this:* !.gitignore !.bashrcand I commit
.gitignoreand.bashrcI move to ~/src/test, which is not a git repository
If I now run git status, the message I would like to see returned is
fatal: Not a git repository (or any of the parent directories): .git
Instead, I will see
# On branch master nothing to commit (working directory clean)
because git status went up the directory tree and found the .git file in my home directory, even though I have ignored the working directory in that repo.
The only solution I see is to set the GIT_DIR for the repo in my home directory to something like .home.git, and then run all of my git commands for that repo as
git --git-dir=~/.home.git --work-tree=~ <command>
I could alias that, but I feel like there is probably a better way to configure git to do this.