Deleting files in Git

Deleting files in Git 1

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 --- filename.py 

Command to delete the entire directory

git rm -r -- /path/ 

Command to delete a file with force

git rm  -f --- filename.py 

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 Git 2

if user have staged the files that need to be deleted, the user should use -f force tag

Default image
Vishal Devxo
Vishal Devxo is a DevOps engineer and a Backend developer, he spends all his time for creating good tutorials with better visuals and blogging, developed some projects based on Python-Django, some hacking modules and scripts in python