DEV Community

Ranjith Kumar Nagella
Ranjith Kumar Nagella

Posted on

Clean up untracked files in git repository based on .gitignore

Why am I here?
Photo by Jon Tyson on Unsplash

The other day I had created a new React Native module project and pushed it to the git repository. Then later, I added the file .gitignore. Since we added it later, these files will still exist in our repository index. How can we clean them up?

  1. Commit all your local changes including .gitignore
    git commit -am "file changes"

  2. Remove everything from the repository
    git rm -r --cached .
    # --cached will only remove files from the index.
    . Indicates all files will be untracked
    or
    you can un-track individual files
    git rm --cached ios/Pods

  3. Re-add everything
    git add --all

  4. Commit the files
    git commit -m "cleanup .gitignore files"

Top comments (0)