Resolving .gitignore Not Ignoring Already Tracked Files
Nov
24

Resolving .gitignore Not Ignoring Already Tracked Files

Many of us encounter an issue where .gitignore doesn't seem to ignore files as expected. This usually happens with files that were already tracked by Git before being added to .gitignore. .gitignore only works for untracked files, so previously tracked files need to be manually untracked.
Following are the steps to fix this issue.

Step 1: Remove Files from Index

Use git rm --cached to remove files from the index, keeping them in your working directory.

git rm --cached FILENAME  # For individual files
git rm --cached -r DIRECTORYNAME  # For folders/directories

This command un-stages the files, stopping them from being tracked, but does not delete them from your file system.

Step 2: Commit Changes

Commit these changes to your repository:

git commit -m "Stop tracking"

This commit removes the tracking status of the files.

Step 3: Push Changes

Finaly! push your changes:

git push

That’s it.

Contact

Get in touch with us

Feel free to request missing tools or give some feedback.

Contact Us