Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a folder from a repository in github?

Tags:

git

I want to remove a folder from a repository in GitHub, i have pushed it as an attempt to try some git commands, but now i can't delete it, i tried with git rm -r --cached folder name and git tells me that it doesn't match any file. my objective is to keep the local folder and deleting it only from git. Thanks for help!

like image 849
Daniele Caliari Avatar asked Mar 06 '26 12:03

Daniele Caliari


1 Answers

Note: since January 2021, you can also delete that folder directly on GitHub.

Delete directory from the web

You can now delete an entire directory of files including subdirectories from your web browser:

  • Browse to the directory in the repository and branch that you want to delete
  • In the top-right corner, click "", and then Delete directory
  • Review the list of files
  • Depending on your permissions and the branch protection rules, choose to either commit the change directly or propose the change using a pull request

Learn more about deleting a file or directory.

https://docs.github.com/assets/images/help/repository/delete-directory-button.png

Then you can fetch, and then restore/update your local branch, without deleting the (now) deleted remote files

git fetch
git read-tree origin/main
git checkout-index -f -a
git update-index -q --refresh
like image 74
VonC Avatar answered Mar 09 '26 00:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!