How to identify untracked files that Git should intentionally ignore when running numerous commands, such as
git add -u,
git clean and many more.
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.*.* *.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
# # 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
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):
.gitignorefile 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
.gitignorefile. A project normally includes such
.gitignorefiles in its repository, containing patterns for files generated as part of the project build,
.gitignorefile that comes with the repository.
$GIT_DIR/info/excludefile for that repository after the user has cloned it.
core.excludesFilein the user’s
$ git config --global core.excludesfile ~/.my_ignorefile
$ man git-check-ignore
.gitignoreis a versioned file, checking out a different commit might result in a different
.gitignorefile, causing unexpected behaviour.