Every Mac user has had this happen to them. You write some code, push your changes up to a repository, and that’s when it happens. There’s .DS_Store files across your repository.
In the Apple macOS operating system, .DS_Store is a file that stores custom attributes of its containing folder, such as the position of icons or the choice of a background image.
tldr; the OS uses it to store metadata for the folder
To fix this, you could rewrite your Git history but you’ll end up having to do this every time the .DS_Store file appears. This isn’t a great solution.
You could a new rule to your .gitignore file. This requires you to remember to add .DS_Store each time. This is a better solution but still not ideal.
Just as the .gitignore file in each of your repositories tells what files Git should ignore, the .gitignore_global applies rules across all the repositories on your machine.
The .gitignore_global file can be created by entering the following:
git config — global core.excludesfile ~/.gitignore_globals
After you’ve created the file, you can add rules just as your would in a .gitignore file.
So what now? You can start adding files that you don’t want to get committed into .gitignore_global. You can find a list of example config files based on what you’re developing here.
Also, if you want to stop the creation of .DS_Store, you can enter the following command into your Terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
After rebooting, your OS will stop creating those pesky .DS_Store files.
To undo the above command, enter the following command into your Terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores false
This is a cross post from the GitHub Campus Experts Blog.