Google Cloud

How to Remove All Files in a Git Repository

How to remove all files in a Git repository. By default we can delete only one file from a branch in a git repository. But if you need to delete all files and folders from the branch and make fresh start you need use the command line tool to remove all folders and files.

In this guide you are going to learn how to remove multiple files and folders from your git repository.

Choose Best Hosting for your Business

PlatformReviewsPricing
Siteground★★★★★$3.95
Kinsta – Google Cloud★★★★★$30

Prerequisites

Git installed in your local machine.

Step 1: Clone Repository

To delete the files and folders in your repository you need to clone the repository to your local machine using the git clone command.

git clone repository_url.git

This command will pull the master branch of your repository.

If you want to pull a specific branch you need to use the -b option with the branch name.

git clone repository_url.git -b branch_name

Step 2: Choose Correct Branch

Once you have pulled your repository you need to make sure you are in the correct branch.

To check the branch you are working on you can use the status command.

git status

To change the branch name you can use the checkout command.

git checkout branch_name

Step 3: Remove Files and Folders

Now you can proceed to delete the files and folders using the rm command.

If you are deleting the folders and files within you need to use the recursive option -r to delete them all.

git rm -r folder_1 folder_2 file_1 file_2 

This command will delete all the included files and folders in your local system.

Now, if you check your local system you can see the files and folders will get removed.

Step 4: Make Commit

Once you have deleted all the files and folders you need to perform a commit.

git commit -m "Removed files and folders"

Step 5: Push to the Remote Repository

Now you can push the changes to the remote repository so that you will have all changes made in the local system.

git push

Now you can see the changes also reflected in your remote repository.

Conclusion

Now you have learned how to remove files and folders from your Git repository at once.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

If you find this helpful? Support me!
Buy me a coffee Donation Please buy me a coffee