Steps to clear out or reset the history of a git repository

You, GitUtility

Resetting and clear out a repository will completely erase your code and all repository history. If you need this data, make a backup now before proceeding.

There are some approached out there on StackOverflow like remove the .git folder, I've tried them never worked. If you have access to your remote repository settings you can just drop the remote branch but remote repository needed to have a special settings for that.

receive.denyDeleteCurrent would do that.

I don't have access to my remote repo configs so not going to do that.

I followed the following steps.

  1. If you already have the repository initialized then remove the .git folder.
rm -rf .git
  1. Re-create the repo with only current content.
git init
git add .
git commit -m "Initial commit"
  1. Now add the remote origin Git repository
git remote add origin [repo_address]
  1. Push the changes to the remote repository.
git push --mirror --force
© Heshan Wanigasooriya.RSS

🍪 This site does not track you.