What is a .gitignore file?
Git Ignore Rules File · Code and data · Git project · 2005
A .gitignore file tells Git which files and folders to leave out of version control: build output, dependencies, secrets and editor clutter. It sits in a repository, usually at the root, and is plain text.
What is a .gitignore file used for?
Each line is a pattern: node_modules/ ignores a folder, *.log ignores by extension, and a leading ! re-includes an exception. Patterns apply to the directory the file sits in and everything below it.
One catch trips everyone up: .gitignore only affects untracked files. If a file was already committed, adding it to .gitignore does nothing until you remove it from the index with git rm --cached.
How to open a .gitignore file
The .gitignore format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .gitignore file.
Windows
- any text editor
- VS Code
macOS
- any text editor
- VS Code
Linux
- any text editor
- VS Code
.gitignore file signature (magic bytes)
Programs recognise a .gitignore file by the bytes at the start of the file, not by its name. These are the signatures for gitignore.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .gitignore file?
A .gitignore file tells Git which files and folders to leave out of version control: build output, dependencies, secrets and editor clutter. It sits in a repository, usually at the root, and is plain text.
Why is my .gitignore not working?
Almost always because the files were committed before the rule was added. Run git rm --cached on them (they stay on disk), commit, and the rules apply from then on.
Where does the .gitignore file go?
Usually in the repository root, but any folder can have its own. Git also supports a global ignore file for personal editor and OS clutter across all repos.
How do I create a .gitignore on Windows?
Save a file named exactly .gitignore (no other extension) in the repo. If Explorer resists names starting with a dot, create it from an editor or with a terminal.
Related formats
Sources
Details on this page were checked against authoritative references: