If you are using a Mac, chances are that you have a lot of .DS_Store
files in all kinds of folders. While they don’t cause any problems, it might be ugly if these files appear in your GitHub repositories. How to delete and ignore all of them? This thread
on Stack Overflow helped me quite a bit.
First, delete all .DS_Store files #
The following solution came from here .
At the root of your local repository1, run:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
git add .
git commit -m "Remove .DS_Store from everywhere"
git push origin master
Second, create a .gitignore file and ignore .DS_Store #
The following solution came from here and here .
If you don’t have it in your repository yet, create one:
touch .gitignore
echo \.DS_Store >> .gitignore
git add .
git commit -m "Creating .gitignore and ignore .DS_Store"
git push origin master
Third, exclude all .DS_Store files in all repositories in the future #
The following answer came from here
If you want to exlude all .DS_Store files from your future repositories:
echo .DS_Store >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
-
All the codes in this post are supposed to be run at the root directory of your local repo. ↩︎
Last modified on 2021-10-05