How to Ignore Files That Have Already Been Commited To a Git Repo.

How to Ignore Files That Have Already Been Commited To a Git Repo.

easier-docs-git-hero-image

Normally, .gitignore will not track files that have been mentioned in it.
But if it was already being tracked by git and addded to .gitignore later, it will still be tracked.

To stop Git from doing this, we have to use the git rm command to remove a file from git.

git rm

git rm --cached <file>

Ignore a folder

If it is a folder instead of a file, use the -r recursive flag to remove all the files in the directory and it’s subdirectories from git.

git rm -r --cached <folder>

Commit the changes

Finally You need to commit the changes. This will remove the file from other’s sharing the same repo when the pull the latest commit but it wont remove the file for you.

git commit -m "removed file"
Last updated on