macOS .gitignore template
The macOS template ignores the metadata files the file manager writes into any directory it displays, plus the indexing, backup and network volume artefacts.
At a glance
- Category
- OS
- Patterns in this template
- 17 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
- Windows and Linux if anyone on the team uses either. They cost nothing to add.
In detail
.DS_Store is written by the file manager, not by anything you ran. Opening a folder in a window is enough: the file records the view style, icon positions, sort order and window size for that directory. That is why it appears in directories nobody has edited, including asset folders somebody merely browsed while looking for a file, and why it turns up over and over after being deleted.
It is small and harmless in itself, but it produces a steady stream of pointless commits and it leaks a little information about the folder structure and view preferences of the person who committed it. On a mixed team it is also invisible to everyone else, so nobody but the macOS users notices the noise accumulating.
._* covers AppleDouble files. When a macOS file with extended attributes or a resource fork is written to a filesystem that cannot store them, the metadata is split into a companion file with that prefix. Copying a project to a memory stick and back is enough to scatter them through a tree. .AppleDouble and .LSOverride belong to the same mechanism.
The system service rules cover .Spotlight-V100, which is the search index, .fseventsd, which is the filesystem event log, .DocumentRevisions-V100, which is the versions database, and .TemporaryItems and .Trashes. These appear on volumes rather than in ordinary project folders, which is why they matter mostly for a repository stored on an external or network drive.
Network Trash Folder, Temporary Items, .AppleDB, .AppleDesktop and .apdisk are the network volume equivalents, created when a macOS machine mounts a shared drive. Icon with a trailing carriage return is the custom folder icon file, whose odd name is why the pattern needs an escape.
Examples
.DS_Store
.AppleDouble
.LSOverride
Icon\r
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk17 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- Adding this template does not remove .DS_Store files already tracked. Run git rm --cached on them, or the file keeps being committed no matter what the ignore file says.
- A global ignore file in your home directory is the better home for this template, because .DS_Store follows the person rather than the project.
- The Icon pattern relies on a carriage return in the filename. Retyping the rule by hand usually produces a version that matches nothing.
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 →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.
Linux .gitignore template
The shortest template in the collection. Five rules covering editor backup files, file manager settings, per volume trash and NFS silly rename files.
Xcode .gitignore template
The Xcode template ignores the project bundle's contents while keeping the project file and shared data, the only way to share schemes but not sessions.
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