My home directory is a git repository. But to allow me to freely create/delete/test code without cluttering up git status
, my .gitignore has an explicit ignore all:
[svenglar@my_box ~]$ cat ~/.gitignore
## Ignore everything by default.
## Use 'git add --force <file>' to add a file/dir.
*
I assume that that means when I create a new directory, it will not be included in the repository. But that doesn't seem to be the case:
[svenglar@my_box ~]$ git rev-parse --is-inside-work-tree
true
[svenglar@my_box ~]$ mkdir test
[svenglar@my_box ~]$ cd test
[svenglar@my_box ~/test]$ git rev-parse --is-inside-work-tree
true
[svenglar@my_box ~/test]$ git status
# On branch master
nothing to commit, working directory clean
I see that git status
is clean, but git rev-parse --is-inside-work-tree
thinks the new directory is part of the repository.
So my question is, how can I configure git to not consider new directories to be part of the working tree?
--UPDATE--
The reason I'm asking this in the first place is because I use .git-prompt.sh to modify BASH's prompt when I'm working with my git repos. I have multiple projects (folders) under my home folder that are git repos. When I cd to one of those directories, I like to see which branch is active, etc...
But I don't need/want to use .git-prompt.sh when I'm in the "home" repository because I don't consider that a "work" directory.
My fix is to modify .git-prompt.sh with the following check before the last "printf" command:
# Only modify $PS1 if we are not in the home repository.
[[ $(git rev-parse --show-toplevel) =~ "${HOME}/" ]] && printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
I was previously only checking if pwd
contained ${HOME}/
(the last forward slash meaning I was in a subdirectory).
Thanks for all your answers. They helped me understand why I was wrong.