Step 1: In order to remove existing files from the repository:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Step 2: Add this line '.DS_Store' to your .gitignore file, which can be found at the top level of your repository (or create if it isn't there already. Use the following command to do so:
echo .DS_Store >> .gitignore
Step 3: Then run the following command:
git add .gitignore
git commit -m '.DS_Store banished!'
For more information regarding this git commands and version controlling please go through the below link.