Helpful .gitignore settings for MacOS

Helpful .gitignore settings for MacOS

·

2 min read

Table of contents

No heading

No headings in the article.

I started working on a new tutorial project that involved downloading some images from a zipfile. Running a git status on that directory showed that git was tracking the .DS_Store file that was automatically created in the folder by MacOS. I figured that was something I did not want to be committed to my repo. According to Buildthis a .DS_Store file is:

A .DS_Store, short for Desktop Services Store, is an invisible file on the macOS operating system that gets automatically created anytime you look into a folder with ‘Finder.’ This file will then follow the folder everywhere it goes, including when archived, like in ‘ZIP.’

Initially, I was just going to add this file to my local .gitignore but then I thought about future me having to do this for every directory moving forward. I checked out Github's gitignore docs and learned that you can set up a global gitignore file which would prevent this from ever happening again.

So, I created that file in my home directory and then thought about what else might be good to include globally. Another search led me to gitignore.io. There I looked up "MacOS" and used that to add to my .gitignore_global file.

# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.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

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos

After that file was created and updated, git was no longer tracking that pesky .DS_Store file. And hopefully, this will protect future me from having to deal with these issues :)