Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

November Discount Launch 2022 – TEMP TOP (NPI)
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

1. Introduction

As we know, the .gitignore file prevents future untracked files from being added to the git index. In other words, any files that are currently tracked will still be tracked by git.

In this tutorial, we'll explore different possibilities to remove tracked files from the git index after adding them to .gitignore.

2. Removing a Single File

In order to remove a single file, we first have to add the file name to .gitignore and then run the git rm command, followed by a commit:

git rm --cached <filename>
git commit -m "<Message>"

The first command removes the file from the index and stages the change, while the second command commits the change to the branch.

3. Removing a Folder

We can remove an entire folder by first adding the folder name to .gitignore and running the git commands:

git rm --cached -r <folder>
git commit -m "<Message>"

Notice the -r addition to the command, as without it, the command will fail with:

fatal: not removing 'folder' recursively without -r.

4. Removing All Ignored Files

Here, we're removing all files that are currently being ignored in .gitignore:

git rm -r --cached .
git add .
git commit -m "Removes all .gitignore files and folders"

The first command removes all the files from the index. The second command re-adds all the files without those in .gitignore, and the last command commits the change. After these three commands, all the files from .gitignore will be removed from the index.

5. Conclusion

In this article, we explored three different ways of removing tracked files from the git index.

The above actions will not remove the physical files from our machine but will remove the files from other developers' machines after they pull the changes.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Generic footer banner
Comments are closed on this article!