1

I don't want my MacBook's .DS_Store-files to be committed to my Git repository.

Unfortunately my .gitignore and even .gitignore_global seem to be ignored completely.

Any ideas what could be the reason?

 ujjain:~/Dropbox/workspace| (HEAD) [+1] | feature/Jenkinsfile [+1]
$ cat .gitignore
...

# Mac OS Test
.DS_Store
 ujjain:~/Dropbox/workspace| (HEAD) [+1] | feature/Jenkinsfile [+1]
$ git status
On branch feature/Jenkinsfile
Your branch is up to date with 'origin/feature/Jenkinsfile'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  modified:   .DS_Store

no changes added to commit (use "git add" and/or "git commit -a")
Dennis
  • 2,866
  • 7
  • 32
  • 49
  • Your prompt suggests that you are keeping your Git repository in a dropbox workspace. **Don't.** Dropbox will eventually corrupt your repository. (If you have a backup copy elsewhere the backup will be OK.) – torek Apr 02 '19 at 15:23
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Apr 02 '19 at 17:46
  • https://stackoverflow.com/search?q=%5Bgitignore%5D+remove+tracked+file – phd Apr 02 '19 at 17:47
  • https://stackoverflow.com/questions/107701/how-can-i-remove-ds-store-files-from-a-git-repository – phd Apr 02 '19 at 17:47

2 Answers2

6

Your .DS_Store has been committed before it had been added in the .gitignore. You remove it from your repo with:

git rm --cached .DS_Store
git commit -m '.DS_Store untracked'

The --cached option will remove the file from the index only, but will not delete the file itself.

Once this will be done, the file will not be tracked by Git anymore and will be properly ignored.

padawin
  • 4,230
  • 15
  • 19
5

You may have committed this file previously. Try this to remove it:

git rm --cached .DS_Store
Alex
  • 101
  • 6