Gitignore for macOS
This example generates a comprehensive .gitignore file for macOS development. It includes patterns for .DS_Store files, macOS system files, Xcode artifacts, and other Apple-specific files that shouldn’t be committed to version control.
What’s Included
macOS System Files
.DS_Store: Finder folder settings._*: macOS resource forks.AppleDouble: macOS extended attributes.LSOverride: Finder icon cache.Spotlight-V100: Spotlight index.Trashes: Trash folderIcon?: Custom icon files
Xcode (if applicable)
*.xcuserdata: User-specific Xcode settings*.xcworkspace: Workspace files (usually)DerivedData/: Build artifacts*.hmap: Header maps*.ipa: iOS app archives*.dSYM.zip: Debug symbols*.dSYM: Debug symbols folder
Time Machine
*.backup: Time Machine backups
How to Use
- Click “Generate” to create the .gitignore file
- Copy the generated content
- Create a
.gitignorefile in your project root - Paste the content and save
- If you have existing .DS_Store files, remove them from git tracking
Removing Existing .DS_Store Files
If .DS_Store files are already tracked in your repository:
# Find and delete all .DS_Store files
find . -name .DS_Store -delete
# Untrack them from git
git rm --cached .DS_Store
# Add to .gitignore (if not already there)
echo ".DS_Store" >> .gitignore
# Commit the changes
git add .gitignore
git commit -m "Remove .DS_Store files from tracking"
Global Gitignore (Recommended)
Set up a global gitignore to ignore macOS files in all your projects:
# Create global gitignore
echo -e ".DS_Store\n._*\n.AppleDouble\n.LSOverride\n.Spotlight-V100\n.Trashes\nIcon?" > ~/.gitignore_global
# Configure git to use it
git config --global core.excludesfile ~/.gitignore_global
This way, you never have to add macOS-specific patterns to each project’s .gitignore.