Oscar the owl and Vershd logo
Git ignore already tracked files

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 shown 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.
Vershd is the effortless Git GUI for Windows, Mac, & Linux
Oscar the owl and Vershd logo
 © 2021 Blightysoft
Made in England
St. George's flag of England, the Union Jack flag of the United Kingdom, the European Union flag, and the United Nations flag.
chevron-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram