In this guide, we have explained the method of removing a directory in Git.
How to Remove Directory in Git?
When users have multiple directories or folders in the Git repository, sometimes, they want to delete an unnecessary directory. For the corresponding purpose, try out the below-listed steps.
Step 1: Create Repository
Open up GitHub hosting service and press the “+” icon to create a new repository:
Next, specify the repository name, mark the “Public” option to permit everyone to access it, and click on the “Create repository” button:
Step 3: Launch Git Bash
To launch the “Git Bash” on your system, press the “CTRL + Esc” key to open the “Startup” menu and search it:
Step 4: Navigate to Git Directory
Move to the specific Git directory with the help of the provided command:
Step 5: Copy HTTPS URL
Open the selected remote repository that you want to clone, hit the “Code” button, and copy the “HTTP URL” to the clipboard. Here, we want to clone the “mari_khan” remote repository:
Step 6: Clone Remote Repository
Run the below-given command with copied HTTP URL to clone the repository:
As you can see, our remote repository “mari_khan” is cloned successfully:
Step 7: Navigate to Git Repository
Next, move to the cloned repository using “cd” command:
Step 8: Create Git Directory
Next, run the “mkdir” to create a new directory under the cloned repository:
Move to the “My_dir” directory by utilizing the given command:
Step 9: Create and Update File
Execute the “echo” command to create and update a file named “File1.txt” in the Git directory:
Step 10: Add File into Git Directory
Add the created file into the Git directory:
Step 11: Navigate to Git Repository
Next, navigate back to the Git repository:
Step 12: Check Status
Now, check the Git repository status:
Step 13: Check Git Repository List
Check the list of Git repositories:
Below output indicates that we have “File1.txt” file in Git repository:
Step 14: Remove Git Directory
Remove the Git directory using the “rm” command with “-r” flag:
Here, the “-r” option will remove the “My_dir” directory recursively:
Step 15: Check Status
Again, check the Git status:
Below output shows that our specified Git directory is deleted successfully:
We have provided the process of removing the directory in Git.
Conclusion
To remove the directory in Git, first, create a new remote repository, open up the “Git Bash” terminal, and navigate to the directory. Copy the “HTTP URL” and paste it to the terminal to clone it to the Git repository. Next, create and move to the Git directory. After that, create and update the file using and execute the “$ rm -r” command to remove the directory. In this guide, we have explained the method of removing a directory in Git.