Mattia Orfano
Posted on June 12, 2022
Hello everyone, and welcome to #10stips! The column where you learn how to solve coding issues within 10 seconds.
In today's episode I show you how to .gitignore MacOS .DS_Store files in every folder and subfolder of your project.
A little bit of background
I recently jumped onboard onto an existing Rails 4 project.
Yes, Rails 4 is still widely used in production and oftentimes is particularly challenging to upgrade an application with newer Rails versions without creating breaking changes.
As soon as I cloned the repository, and opened up the code with Atom, I noticed all those magical .DS_Store files.
"Fuck! Back up little bastards!"
How to .gitignore .DS_Store files
First, unmatch previously committed files:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Then, add **/.DS_Store
into .gitignore
Finally, commit and push the changes:
git commit -m "Remove .DS_Store from everywhere"
git push
You're welcome!
Now, your Mac will still create .DS_Store files in every folder. If you become frustrated, you can turn them off.
(bonus) How to turn off the creation of .DS_Store files
Mac creates the .DS_Store files to retain settings configured for each folder such as the size and orientation of icons, sort settings, and so on.
If you become frustrated, you can turn off the creation of .DS_Store files - just execute the following command in Terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
Reboot your Mac, and you’ll be good to go.
Posted on June 12, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.