Linux .gitignore template
The Linux template is five rules long, covering tilde backup files, file manager metadata, per volume trash directories and the temporary files NFS creates.
At a glance
- Category
- OS
- Patterns in this template
- 5 rules
- Directories ignored
- None. Every rule matches by filename or extension rather than by directory.
- Also needs an OS template
- This is the OS template. Pair it with a language and an editor template.
- Typical companions
- macOS and Windows if the team is mixed, plus your editor's template.
In detail
This is the shortest template in the collection, and the reason is structural. Linux desktops do not write metadata files into every directory you open, so there is simply less debris to cover. What remains comes from a handful of specific tools rather than from the system itself.
*~ is the tilde backup file convention, produced by Emacs by default and by several other editors as an option. It is a copy of the previous saved version, written beside the original. Because the convention is shared across tools, this one rule covers backups from most of them at once.
.directory is the metadata file the KDE file manager writes, holding the view settings and custom icon for a folder. It is the closest equivalent to what the macOS and Windows file managers produce, and it appears only when someone using that desktop has customised the folder.
.Trash-* covers the per user trash directories created on a mounted volume. When you delete a file from a drive that is not your home filesystem, the file manager moves it into a trash directory named with your numeric user id at the root of that volume. A repository living on an external drive can collect one.
.nfs* files are the interesting case. When a file is deleted on an NFS share while a process still has it open, the server renames it to a hidden .nfs file instead of removing it, so the open handle stays valid. The file disappears when the last handle closes. .fuse_hidden* is the same mechanism in a userspace filesystem.
Examples
*~
.fuse_hidden*
.directory
.Trash-*
.nfs*5 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- *~ is a generic suffix, so a file deliberately named with a trailing tilde is ignored along with the editor backups this rule targets.
- None of these five rules cover editor swap files. Add the template for the editor you actually use, because that is where most of the noise comes from.
- This template is a good candidate for a global ignore file in your home directory rather than a per project one, since it describes your machine rather than the project.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →macOS .gitignore template
Where .DS_Store actually comes from, why it appears in folders nobody edited, and what the rest of the macOS template covers on network and removable volumes.
Windows .gitignore template
What the Windows template covers: the thumbnail caches Explorer writes into image folders, the folder view settings file, and installer package extensions.
Vim .gitignore template
The Vim template uses character ranges to catch every swap file extension the editor cycles through, plus sessions, undo history and the netrw history.
Gradle .gitignore template
Six rules covering the Gradle cache and build directories, with negations that keep the wrapper jar and properties tracked because a clone needs both.
Maven .gitignore template
The Maven template ignores the target directory and the backup files the release plugin leaves behind, including the wrapper jar that Gradle keeps.
npm .gitignore template
This template ignores package-lock.json, which contradicts the current advice to commit the lockfile. Here is what the rest of it covers and what to change.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- Git Commit Message Generator Free online git commit message generator - generate conventional commit messages with type, scope, and description