Deleting files in Git

Deleting files in Git

we might do some mistakes in code .or we have some bugs in our code and if we need to delete some extra unnecessary files, we can remove these files from the working tree, this stops tracking changes for that file.we should use git -rm command. this command will only delete a specific file in the current directory .we can restore the deleted file from the previous history of our repo.

Command to delete a single file

git rm ---

Command to delete the entire directory

git rm -r -- /path/

Command to delete a file with force

git rm -f ---

above commands deleted the file both in the filesystem and the index, to delete files only in the repository, use the below command

git rm --cached filename.txt

Command to delete same extension files

The user might need to delete the same set of files like registry files or any specific language files, use below command to the deleted same type of extension files

git rm -- *.Extension
Deleting files in Gitif user have staged the files that need to be deleted, the user should use **-f** force tag
Last updated on by vishal devxo