Resolving .gitignore Not Ignoring Already Tracked Files
Nov
24
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.
Famous Posts
New Posts
How to Copy Files and Folders in Linux While Preserving Owners and Permissions
How to Send Asynchronous Requests with cURL in PHP
Fortifying Your Foundation: Best Practices for Securing Your Laravel Application
Don't Block Your Users! Leverage Laravel Queues for a Smooth User Experience
Passport vs. Sanctum: Choosing the Right Authentication for Your Laravel Application