Delete a file from a git repository
Posted by SceDev
Last Updated: February 08, 2024

Want to delete a file from a Git repository?

 

The following command will delete a file from a repository and the filesystem.

git rm example.txt
git commit -m "Deleted example.txt from the repository"

 

The following command will delete a file from a repository but keep it in the filesystem.

git rm --cached example.txt
git commit -m "Deleted example.txt from the repository"