As a macOS developer, you've probably encountered this frustrating scenario: you commit your code, only to realize you've accidentally included .DS_Store files and other macOS system files in your repository. These files clutter your commits and can be embarrassing when working on team projects.

The solution? Set up a global Git ignore file that automatically excludes these system files from all your repositories. Here's how to do it properly.

Why You Need a Global Git Ignore

Instead of adding macOS-specific files to every project's .gitignore, a global ignore file handles system-level exclusions across all your repositories. This keeps your project .gitignore files clean and focused on project-specific files.

Step 1: Check Your Current Setup

First, let's see if you already have a global Git ignore configured:

git config --get core.excludesfile

What to expect:

  • If you see a file path (like /Users/yourusername/.gitignore), you're already set up
  • If there's no output, you need to create one

Step 2: Create Your Global Git Ignore File

Create the file

touch ~/.gitignore

Add macOS system files

Open the file in your preferred text editor and add these common macOS system files:

# macOS system files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# macOS Finder attributes
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

Configure Git to use your global ignore file

git config --global core.excludesfile ~/.gitignore

Step 3: Verify Your Setup

Confirm everything is working:

git config --global core.excludesFile

This should return the path to your global gitignore file.

Clean Up Existing Repositories

If you already have .DS_Store files tracked in your repositories, remove them:

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch

Then commit the removal:

git commit -m "Remove .DS_Store files"

Pro Tips

  • File location flexibility: You can use any location for your global ignore file (like ~/.config/git/ignore) as long as Git knows where to find it
  • Team consideration: Global ignores handle personal/system preferences, while project .gitignore files should focus on language and framework-specific files
  • Regular updates: Periodically review and update your global ignore file as you discover new system files to exclude

The Result

With this setup, you'll never accidentally commit macOS system files again. Your repositories will stay clean, your commits will be more professional, and your teammates will thank you for not cluttering the project history with system files.

Your global Git ignore file works silently in the background, making your development workflow smoother and more professional. Set it up once, and enjoy cleaner repositories forever.


Found this helpful? Share it with your fellow macOS developers and help keep Git repositories clean across the community.

Stop Committing macOS System Files: The Complete Guide to Global Git Ignore