Remove .DS_Store files

DS_Store file is acronym of Desktop Service Store. In Xcode app, we can have more than one .DS_Store files.
How to remove DS_Store files via .gitignore
We can use gitignore file for handling .DS_Store files but note that we cannot delete .DS_Store files via a .gitignore file, but we can prevent them from being tracked by Git.
Steps to create .gitignore
Open Terminal and follow steps
Step1: Navigate to location for Git repo/project.
Step2: Create a .gitignore file via following command on terminal
touch .gitignore
The .gitignore
file tells Git which files to ignore. To stop .DS_Store
files from being tracked, add the following line to your project's .gitignore
file
.DS_Store
This ensures that any .DS_Store
files in your project won't be included in future commits.
Remove Tracked
.DS_Store
Files
If .DS_Store
files are already tracked in your repository, you need to remove them. Run the following commands:
Step 1: Find and remove .DS_Store files
find . -name ".DS_Store" -print -delete
Step 2: Update Git’s index:
git rm --cached .DS_Store
Step 3: Commit the changes:
git commit -m "Remove .DS_Store files"
Now we can push the changes on Git repo.
And DONE for your repo. 🎉
Global Ignore for .DS_Store
Now if we want to ignore.DS_Store
files are ignored in all repositories on your machine, we can do following steps
Step1 : Create or edit the global .gitignore
file:
git config --global core.excludesfile ~/.gitignore_global
Step 2: Add .DS_Store
to the global .gitignore
echo ".DS_Store" >> ~/.gitignore_global
Step 3: Verify the global setting
git config --get core.excludesfile
And done 🎉🎉 Now .DS_Store
files will be ignored in all repositories.
Bonus::
Now For macOS, we can prevent Finder from creating .DS_Store
files on network drives with this terminal command:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
CHEERS 🎉🎉🎉