Oscar the owl and Vershd logo

Git Ignore Already Tracked Files

16th March 2020

This is part of a Git Tips series. For the complete set for beginner and intermediate Git users, see our white paper.

The Problem

You have a file committed to Git called hack-to-fix-bug.ts that you previously needed in your repository, but don’t any more since your colleague Gandalf did a far better fix, in a fraction of the time.

Adding a file to the .gitignore file is a good way of ignoring untracked files, although you can override it by forcing the addition of the file to the index by using git add –f on the file.

But how can you get Git to ignore committed files, and prevent them from constantly being show as available to commit every time you edit them?

The Solution

Warning: It’s important to note that the solution for this will ultimately delete the file from everyone else’s machine the next time they run a git pull. It can then be added back into their working files manually, and thereafter ignored by Git.

In this example, you have just one file to ignore.

Firstly, add the file to your .gitignore file via your file explorer:
... Add files to .gitignore...
This removes the file from the index (specified by the --cached parameter). It also marks it for deletion, but not from your disc:
git rm --cached hacks/hack-to-fix-bug.ts
Or use this version, which removes all files in the specified folder:
git rm -r --cached hacks
If you’re nervous, then see what will happen without making changes using this:
git rm --dry-run -r --cached hacks
Carry on changing other files, and commit. The ignored file will stay on your disc, and will be ignored from now on:
git commit –m "Happily ignoring the right files now"

The Quickest & Easiest Solution

Do you need a Git GUI that's totally free for personal use? Vershd boosts your software development productivity by making Git simple with a unique UI/UX. It's a Git GUI that prevents errors and creates clarity. This Git client soars over your repository and then swoops down to quickly tackle branches, commits and files. It deals with Git, so you can concentrate on coding.

Get screenshots and a 60 second video of what Vershd, the effortless Git GUI can do for you.
Oscar the owl and Vershd logo
 © 2020 Blightysoft
Made in England
St. George's flag of EnglandThe Union Jack, the flag of the United KingdomThe European Union flagThe United Nations flag
chevron-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram