Home > Net >  How to delete *all* files in a github repository, and also remove the upstream info?
How to delete *all* files in a github repository, and also remove the upstream info?

Time:07-22

Basically I cloned a git repository and started coding on it, but it still shows the original collaborators and their commits on my repository. Ideally I could fix this without starting over on a fresh repository (have already done a lot to the wiki pages for current repository)

I want my result to look like this:

1.) I rm -rf .git my git files in my local system but keep the original code files

2.) I initialize a new local git repository

3.) I delete all files in my remote repository

4.) I link my new local repository to the remote repository

5.) I git add . my code files so it is now in the remote repository

CodePudding user response:

It's bad practice to overwrite all previous commits like this, as this essentially removes all previous version history and potentially takes away credit from whoever made those previous commits. However, the cleanest way to do this would be to squash all previous commits. This way you don't need to create a new repository at all.

git rebase --root -i

This will open an editor with a list of all of the commits everyone has made. For all of the lines with commits except the first one, add the word 'squash' to the beginning. Then, force push these changes to your main branch. It will have a different first commit so you need to add an extra flag to push.

git push -f origin main --allow-unrelated-histories
  • Related