Removing tracked files in Git that should have been ignored - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Removing tracked files in Git that should have been ignored
===========================================================

### [\#Git](https://rocketeersapp.com/knowledge/git)

Removing files that has been committed earlier in your repository is something you encouter once in a while. Read here how you can do this.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on September 27, 2022 · 1 minute read

1. [The problem](#content-the-problem)
2. [Delete and forget unwanted committed files](#content-delete-and-forget-unwanted-committed-files)

[\#](#content-the-problem "Permalink")The problem
-------------------------------------------------

Anybody that has been using Git for a longer period of time, stumbles every now and then on this pesky little problem: tracked files in your Git repository that should have been ignored from te start. But now they are added, Git can't seem to "forget" about them.

I know I have faced this one a bunch of times! And here's how you can fix this issue and make you feel all clean and happy about your repository again.

[\#](#content-delete-and-forget-unwanted-committed-files "Permalink")Delete and forget unwanted committed files
---------------------------------------------------------------------------------------------------------------

In this example we have the common situation where you've forgot to add `.DS_Store` to your global or repositories `.gitignore` file on your Mac (for Windows users there is a different but evenly annoying `Thumbs.db` that gets created now and then).

 ```
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

```

What does this command do?

1. First it deletes every file that matches `.DS_Store`;
2. Then it pipes these files to the `git rm` command that makes sure Git doesn't keep tracking these files.

Without removing the traces of these files in Git, the `.DS_Store` files that were tracked will eventually pop up again in your working copy.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Git](https://rocketeersapp.com/knowledge/git)

- [Change casing of file or directory in Git](https://rocketeersapp.com/knowledge/change-casing-of-file-or-directory-in-git)
- [Git fatal: refusing to merge unrelated histories](https://rocketeersapp.com/knowledge/git-refusing-to-merge-unrelated-histories)
- [GitHub Permission denied (publickey)](https://rocketeersapp.com/knowledge/github-permission-denied-publickey)
- [Git fatal: not a git repository](https://rocketeersapp.com/knowledge/git-not-a-git-repository)
- [Git: Updates were rejected (non-fast-forward)](https://rocketeersapp.com/knowledge/git-updates-were-rejected-non-fast-forward)
