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.
What opens 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.
Windows
- any text editor
- VS Code
macOS
- any text editor
- VS Code
Linux
- any text editor
- VS Code
Open a .gitignore file step by step
- Confirm the file really is a .gitignore. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with any text editor or VS Code.
- On Mac, use any text editor or VS Code.
- On Linux, try any text editor or VS Code.
- Still stuck? Search for a dedicated gitignore viewer rather than a generic one.
Why can't I open my .gitignore file?
Almost always because no installed app understands gitignore. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .gitignore at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
gitignore has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.
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. How sources are ranked and what is deliberately left out is set out in the methodology.