Remove Accidentally Committed File from Git

We've all done it before, accidentally committed a file we shouldn't

ebeeraheem

View Profile
90 views
Jun 21, 2025

Add the file or folder to .gitignore

Remove the tracked file or folder from git working directory by running the following command

git rm -r --cached <name of file or folder>

Commit the changes

git commit -m “Remove <name of file or folder> from tracking”

Then push the changes

git push origin main

This will ensure that the file or folder is ignored by Git and won’t be included in future commits.