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.
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
To change the branch name you can use the
git checkout branch_name
Step 3: Remove Files and Folders
Now you can proceed to delete the files and folders using the
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.
Now you can see the changes also reflected in your remote repository.
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.