Sometimes we want to delete folders from GitHub but there is no option in
GitHub to delete folder directly. If you want to delete folder from
GitHub then we need to open the folder and delete all files one by one and then the folder will be automatically disappeared / deleted.
In git repository, the folder should not exist without even one file. If no file exist in the folder then automatically the folder will be deleted.
Even if you want create folder, then we should create/add one file in that folder.
Create New Folder in GitHub
Table of Contents
But here if you have N..number of files in the folder to delete then it is tedious process. To overcome this tedious process, we can delete that folder from git bash from local git repository.
Create New Folder from GitBash
Create new folder with name Folder1 and then add file like sample.txt and then add to stage, commit and then push to remote repository.
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial (master)
$ mkdir Folder1
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial (master)
$ cd Folder1/
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
$ touch sample.txt
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
./
nothing added to commit but untracked files present (use "git add" to track)
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
$ git add .
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
$ git commit -m "new folder creted"
[master c2d57a0] new folder creted
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 Folder1/sample.txt
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 331 bytes | 110.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/NarayanaTutorial/NarayanaTutorial.git
73535af..c2d57a0 master -> master
narayana@DESKTOP-IQB300B MINGW64 /d/narayanatutorial/NarayanaTutorial/NarayanaTutorial/Folder1 (master)
Delete New Folder from Github Console
Open the folder(Folder1) in github then go to list of files and then delete one by one by clicking on delete icon highlighted in the below image. When last file delete then the folder (Folder1) will be deleted automatically.
After deleting the file, folder (Folder1) deleted automatically.
Delete folder from GitBash
First up all you can clone or pull the git repository. if you are already working on the same remote repository then you can use full else clone the project into local system
Here I am executing git pull command to sync my local repository.
Step 1
git pull
Step 2
git rm -rf Folder1
Step 3
git rm -rf Folder1
Step 4
git add .
Step 5
git commit -m “Folder1 deleted”
Step 6
git push
You can see the final output from Github
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.