Skip to main content

Resetting A Repository

Steps to reset a GitHub repository:

  1. if (!repository), clone the repository:
git clone <remote repository>
cd <repository>
info

To check the current remote url of the repository:

git remote -v
  1. Remove all git history:
rm -rf .git
  1. Reinitialize git:
git init
  1. Reconnect the repository to GitHub:
git remote add origin <remote repository url> 
  1. Create a new commit:
touch README.md # Add at least one file to commit
git commit -m "Reset repository"
  1. Force push to GitHub:
git push --force origin main

Replace main with the branch name if it's different.

caution
  • This completely erases all previous commits and files.
  • GitHub will not retain old versions after the force push.