.gitignore
A .gitignore file is a configuration file used by Git to tell it which files or directories it should ignore (not track, not stage, not commit) in a repository.
When you create or modify files in a Git repository, Git normally tracks changes so they can be committed.
A .gitignore file defines patterns for files that Git should not show as untracked, not suggest for staging, not include in commits
.gitignore Rules
The rules for the patterns you can put in the .gitignore file are as follows:
- Blank lines or lines starting with
#are ignored - Standard glob patterns work, and will be applied recursively throughout the entire working tree
- You can start patterns with a forward slash
/to avoid recursivity - You can end patterns with a forward slash
/to specify a directory - You can negate a pattern by starting it with an exclamation point
!
Here is another example .gitignore file:
# ignore all files end with .a
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
# ignore all files in any directory named build
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf
Note:
In the simple case, a repository might have a single
.gitignore file in its root directory, which applies recursively to the entire repository. However, it is also possible to have additional .gitignore files in subdirectories. The rules in these nested .gitignore files apply only to the files under the directory where they are located. For example the Linux kernel source repository has 200+ .gitignore files.