Oscar the owl and Vershd logo
Menu

How to Git Ignore Already Tracked Files Effortlessly

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"

Free

GitBreeze is an effortless Git GUI that's free for use at work, at home, anywhere. It boosts software development. It works on Windows, macOS, and Linux.

Designed for developers who want Git to be simple, our unique UI/UX boosts your software development - learn more and reap the benefits.

Help & tools

We provide these pages to try to make your programming life easier. Our resources page gives an overview. You can see a full list of our Git tips & tools here.

We have these free tools:

Customers say...

I love any tool that makes my life easier... This is perfect, just the right amount of control. No more, no less. Easy to get started, push and rollback changes... It's a no brainer!
Hayden T.
Oscar the owl and Vershd logo
 © 2024 GitBreeze Ltd.
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