DEV Community

Regular 🍟
Regular 🍟

Posted on

Remove .DS_Store File from Git Repo

Time: 2021-03-31 08:43 UTC+8:00

Author: vonhyou

.DS_Store is a file that stores custom attributes of its folder (like icons). .DS_Store is a abbr. of Desktop Service Store . This file is similar to the desktop.ini in Windows OS. So that, it's not necessay to add this file into a git repo. Let me tell you how to remove it by adding .gitignore rules.

  1. If you had already add .DS_Store files into a git repo, you have to delete it using command below:
$ find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Enter fullscreen mode Exit fullscreen mode
  1. Append a rule to .gitignore file
$ echo .DS_Store >> .gitignore
Enter fullscreen mode Exit fullscreen mode
  1. Update repo
$ git commit -am "remove .DS_Store files"
Enter fullscreen mode Exit fullscreen mode

If you don't want to repeat it, it's possible to set this rule globally.

  1. Creat a new file called .gitignore_global (or any other you like )
$ touch ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode
  1. Assign this file as a global rule set
$ git config --global core.excludesfile ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode
  1. Add the rule to .gitignore_global
$ echo .DS_Store >> ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode

Done.

Top comments (2)

Collapse
 
rudra0x01 profile image
Rudra Sarkar

Thanks for sharing.

Collapse
 
ellesatori profile image
Lei • Edited

Thank you for this. I've done it but .DS_Store is still in my repo. I wonder if there's anything I'm missing?