I have a repository including many subdirectories. I know for a fact that I won’t make changes to some of them. Is there a way to tell ‘git status’ and other operations which scan the whole filesystem to not bother with these directories, thus speeding up those operations?
Share
I assume that by “[they] are part of the repository” (in your question’s title) that you mean the subdirectories you want to skip actually contain tracked files and that you want to avoid
git statuschecking on the status of even those tracked files.By default,
git statuswill check all the tracked paths. It does not have any options for skipping a preset list of paths, but it does take pathspec arguments that can be used to specify the paths it should check (implicitly, the other paths will be skipped).To directly use the available available functionality, you have to turn the problem around: How do I show the status only certain files and directories?
The answer is that you just list them on the command line. For example, if we only want to know about
src,doc(both probably directories) andMakefile:Typing that every time would be cumbersome, so you will likely want to use a shell script and/or a Git alias.
However, this only works well if you can define the set of paths you are interested in without saying something like “everything except X, Y, and Z”. Git does not include support for “everything except …” (yet1), so you will have to rely on something else to expand the list and give it to
git status. Some shells have features that can help.Example: Process all the entries in the current directory (including “dot” files/directories) as long as they do not match
.V,.W(i.e. patterns that start with a dot),X, orY:zsh with the EXTENDED_GLOB option enabled (
setopt EXTENDED_GLOB),You can leave off the
(D)if you also have GLOB_DOTS enabled.bash with the dotglob and extglob options enabled (
shopt -s extglob dotglob):ksh (the pattern for “dot” names is a bit odd due to emulating GLOB_DOTS):
And again, you will probably want to wrap these up in a script (or Git alias) instead of typing them in directly.
1
There has been some discussion on the Git mailing about adding support for “negative” pathspecs (“everything except …”) that could let you do this without help from the shell, but there is no firm design or public code yet.