How to remove file and directory from Git repo

In this post I am sharing the command to remove files and folder from git repo.The command will remove files from the working tree and from the index.
Note: Before removing any files and directory it is always a good practice to keep the backup of the data.Hence suggesting to first take the backup of your data.

Follow the given below steps to remove file and directory from git repo

We assume you have already cloned the repository in your system from git server.Here for eg. we are giving the repository name as test-repo

Step 1: Change to Working repository in your system

cd test-repo

Step 2: Here in this step, we will remove both file and directory

To remove the file from working tree and index,run the below command

git rm file-name

To remove directory,from working tree and index,run the below command

git rm -r dir-name

Note: If you want to remove all files and directory at a time,then change to directory and run below command. Here in below given command period(.) means from current location.

git rm -r .

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.