How To Delete A Folder In GitHub?

529 Views
0 rating based on 0 reviews

Folders are great for organizing files, but should you create a folder and then wonder how to delete it? You’re not alone. This is a common issue. Often times we create a folder and if we haven’t been given specific instructions on how to delete it, we can get stumped. We want to be able to quickly delete the folder through GitHub while logging into the repository which can be accomplished in a few steps.

Delete a folder in GitHub

GitHub is an online open-sourced cloud-based arena where people share their codes or works for others to view and apply new changes thus providing new ideas for development to the main author. People also upload their work in a folder. If you want to delete your folder from the repository, it may be a bit difficult as there are no direct ways to do so. Here, we have shown some indirect methods for deleting the folder.

From the web

You can delete a file using the delete button but you cannot directly delete a folder via the web-interface. GitHub webpage has no way of doing that. The way to delete a folder from GitHub.com is to delete every file inside it. To do so:

  1. Log in to your GitHub user account by entering your mail and password.
  2. Go to your repositories by Clicking “User option” on the right side of the webpage and click “My repositories”
  3. Click onto the repository from which you wish to delete the files.
  4. Click the file. Go to the right side of the file review webpage and click “Delete”.
  5. Click “Commit Changes” to delete the file.
  6. Similarly, do this to the other files in the folders by deleting them one by one.
  7. If you delete the only file in the folder, GitHub will automatically delete the folder as the folder is empty.

By the Desktop interface

If you use the GitHub application on your desktop, this method will be more suitable for you:

  1. Log in to your GitHub account and go to “My repositories”.
  2. Select the repository from which you intend to delete your folder and clone the repository in your storage. You can also use either Git bash or the Command Prompt depending on your system if they are installed in your system.
  3. Sync the repository back to your GitHub server and it will update your repository.

The code execution

GitHub can remove the folder by running a code. The code iterates over the files in the current folder and looks to delete them. If there aren't any files in a certain folder - GitHub removes it by executing the code. But it takes the help of the prose.io website to execute it. It has an advantage as there is no need to remove multiple files to delete the folder. To delete a folder in GitHub, follow these steps:

  1. Log in to your GitHub account to prose.io website for managing your projects or folders.
  2. Open the desired folder you wish to delete.
  3. Then use this code:

var deleteSuccessful = 0, deleteFailed = 0;

var elements = $('a.delete');

var totalElements = elements.length;

function sleep(ms) {

    return new Promise(resolve => setTimeout(resolve, ms));

}

async function deleteFiles() {

    for (var i = 0; i < totalElements; i++) {

        var element = elements[i];

        var realConfirm = window.confirm;

        window.confirm = function(){

            window.confirm = realConfirm;

            return true;

        };

        try {

            element.click();

            deleteSuccessful += 1;

        } catch (error) {

            deleteFailed += 1;

        }

       await sleep(1000);

    }

    console.log("Total items identified: %dnDeleted: %dnFailed: %dn** Operation %s **", 

        totalElements, deleteSuccessful, deleteFailed, totalElements == deleteSuccessful ? "successful" : "failed");

}

deleteFiles();

Applying this method, you will be able to delete the folders you no longer need.

Summary: Delete a folder in GitHub

  • Go to the repository that has the folder.
  • Click the folder.
  • Click Delete this file at the top of the file view and then commit the change.