Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete the content of github repository?

I wrongly pushed my code using Xcode toolbar into my repository on github. now, I want to delete all files in my master branch, but not the repository. Then I want to pull my code into repository this time instead of pushing. Does any one know how to delete all contents of master branch?

like image 907
MKH Avatar asked Jul 24 '15 10:07

MKH


People also ask

How do I remove contents from my GitHub repository?

In git, you can't delete the content of a branch. All you can do is to push a commit that removes all your files. If you want to start over from a clean repository, you have to delete the current one a create a new one with the same name for example.

Can you delete things from GitHub?

The web interface on GitHub.com allows you to do basic editing tasks. You can delete a specific file after opening its detail view and then clicking on the little trash can icon: However, you cannot delete multiple files in one go nor can you delete folders in the GitHub web interface.

Can I delete history in GitHub repository?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool.


2 Answers

In git, you can't delete the content of a branch. All you can do is to push a commit that removes all your files.
If you want to start over from a clean repository, you have to delete the current one a create a new one with the same name for example.

like image 69
Quentin Hayot Avatar answered Oct 13 '22 00:10

Quentin Hayot


Just to support quentin's answer, adding the git commands:

  1. Keep a backup of the local repository folder and remove all its contents.

  2. Add these changes to commit

$ git add *
  1. Add a Commit message
$ git commit "Remove everything"
  1. Push changes
$ git push -f
like image 24
Pe Dro Avatar answered Oct 12 '22 23:10

Pe Dro