I recently had to untrack a file that was already added to Git. I had to do this because I accidentally commited a file that should be ignored by Git.

I googled for a solution and found this answer on StackOverflow. Sometimes I do this mistake and I always forget how to fix it. So here is a quick reminder for myself and for you.

Steps

1. Commit existing changes

First, commit all your existing changes.

2. Remove cache

Then remove the git cache. I did this by running the following command:

git rm -r --cached .

This will remove the cache for all files in the current directory.

3. Update .gitignore

Then update your .gitignore file to ignore the file you want to untrack.
Now the IDE will show the file as untracked.

4. Commit new changes

Finally, commit the changes.

git add .
git commit -m "Untrack files already added to Git"

5. Push changes

And push the changes to your remote repository.

git push

That's it!

Come back here when you forget how to do it again.