I accidentally pushed the bin
folder of my Java program to GitHub, and now I wish to remove all those .class
files.
How can I do that?
InfoQ: The basic way to remove a binary or other improper file from git is to use the git-filter-branch command.
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.
/bin is usually a folder that contains binary files or compiled stuff in general. You should never put it in a repo. It's not dangerous, but it wastes space and it's something that has to be compiled in each one's computer anyway, so it's pointless to put them in the repo :) Follow this answer to receive notifications.
Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.
First, you should create a commit that removes this folder from git:
$ git rm -r bin
$ git commit -m "Removed bin folder"
$ git push origin master
After doing that, you can ensure this mistake won't happen again by adding the bin
directory to your .gitignore
file, and commit that change too:
$ echo "bin/" >> .gitignore
$ git add .gitignore
$ git commit -m "Added bin folder to gitignore"
$ git push origin master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With