DEV Community

Surhid Amatya
Surhid Amatya

Posted on

4 1

Files added to .gitignore is still being showed untracked file

There is a file that was being tracked by git, but now the file should not be tracked and is added on the .gitignore list.

However, that file keeps showing up in git status after it's edited. How do we force git to completely forget about it and stop tracking it?

To stop tracking the files we need to remove that file from the index.

To achieve this git has provided us with some commands as listed below:

To untrack a single file

git rm --cached filename

To untrack every file

git rm -r - cached .

this code removes any changed files from the index, after this code run

git add .

Now, it's time to commit the changes;

 git commit -m "update .gitignore file"

These mentioned codes will update the .gitignore file but what if we had added the wrong file or if we need to track some files again.

Undo

git rm --cached filename

use

git add filename

to track this file again.
Hope this will help us all.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay