How to identify untracked files that Git should intentionally ignore when running numerous commands, such as git add -u
, git status
, git clean
and many more.
Some links:
Excerpts from the Linux kernel source top-level .gitignore
file, which forces ignoring of all these file patterns recursively:
.* [all hidden files/directories] *.a *.asn1.[ch] *.bz2 *.c.[012]*.* *.dt.yaml *.dtb *.dtb.S *.dwo *.elf *.gz *.ko ... Module.symvers [specific filename] ... # # Top-level generic files # /tags /TAGS /linux /vmlinux /vmlinux.32 /vmlinux-gdb.py ... /debian/ [top-level directory only] ... # # Exceptions: git files that we don't want to ignore even if they are dot-files # !.gitignore !.mailmap !.cocciconfig !.clang-format ... # # Generated include files # include/config include/generated include/ksym arch/*/include/generated ...
Subdirectories can have more specific .gitignore
files that take precedence in those subdirectories. For the Linux kernel source, the top-level directory scripts/
has the .gitignore
file:
# # Generated files # bin2c conmakehash kallsyms pnmtologo unifdef recordmcount sortextable asn1_compiler extract-cert sign-file insert-sys-cert
The Linux kernel source repo has over 200 .gitignore
files.
Each line in a gitignore/exclude file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):
man git-clean
),.gitignore
file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore
file. A project normally includes such .gitignore
files in its repository, containing patterns for files generated as part of the project build,$GIT_DIR/info/exclude
,core.excludesFile
(possibly ~/.my_ignorefile
)..gitignore
file that comes with the repository.$GIT_DIR/info/exclude
file for that repository after the user has cloned it.core.excludesFile
in the user’s ~/.gitconfig
.$ git config --global core.excludesfile ~/.my_ignorefile
$ man git-check-ignore
.gitignore
is a versioned file, checking out a different commit might result in a different .gitignore
file, causing unexpected behaviour.