Git

How to Remove Multiple Deleted Files in Git Repository

Git is a decentralized tool that is used for tracking and managing large development projects. They can create and modify files according to their preferences. Furthermore, they can remove/delete files from the Git repository as well as from the working area. To do so, the “git commit -a” command is useful.

This guide will provide the easiest way of removing multiple deleted files from the Git repository.

How to Remove Multiple Deleted Files in Git Repository?

To Remove the multiple deleted files from the Git repository, follow the provided steps:

  • Redirect to the required Git local repository.
  • Check the current working branch status.
  • Utilize the “git commit -a” command.
  • Verify by viewing the repository status.

Step 1: Redirect to Git Repository

At first, run the “cd” command along with the required repository path and switch to it:

$ cd "C:\Users\nazma\Git\perk1"

Step 2: Show Repository Content

To display the content of the current working Git directory, use the following command:

$ ls

Step 3: Delete Multiple Files

Then, delete the multiple files at once by executing the “rm” command:

$ rm file1.txt file2.txt file3.txt

Step 4: Check Repository Status

Next, run the below-provided command to view the status of the current working branch:

$ git status .

As you can see, the deleted files exist in the working area:

Step 5: Commit Staged/Unstaged Changes

Now, commit all added changes including staged/unstaged with the help of the below-stated command:

$ git commit -a

Here, when the above-given command is executed, it will open the “COMMIT_EDITMGS” file with a default text editor and ask for specifying the commit message. For instance, we have typed “Remove files”:

After specifying the commit message, all deleted files will be removed from the working area:

Step 6: Verify Removing Operation

Lastly, to ensure that all deleted files are removed from the Git working area, execute the following command:

$ git status .

It can be observed that the Git working area is empty, and nothing to commit:

That’s all! We have illustrated the procedure of removing multiple deleted project files from the particular Git repository.

Conclusion

To Remove the multiple deleted files from the Git repository, first, check the current working branch status. Then, execute the “git commit -a” command. Lastly, verify by viewing the repository status. This guide demonstrated the method of removing multiple deleted files from the Git repository.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.