Skip to content

Instantly share code, notes, and snippets.

@alexperronnet
Last active March 16, 2023 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexperronnet/959c63f650eeed2a5f1cd2cf491b82a4 to your computer and use it in GitHub Desktop.
Save alexperronnet/959c63f650eeed2a5f1cd2cf491b82a4 to your computer and use it in GitHub Desktop.
GitHub - Delete commits history from a repository
  1. Create a new orphan branch
git checkout --orphan TEMP_BRANCH
  1. Add all files to the staging area
git add .
  1. Commit the changes with an initial commit message
git commit -m "Initial commit"
  1. Rename the new branch to "main" (or the branch you want to reset)
git branch -M main
  1. Force push the new branch to the remote repository
git push -f origin main

⚠️ This will reset the repository to the new branch state while keeping the history of contributions in the GitHub graph. Please note that this action will overwrite the remote repository's history, so make sure you have a backup of the original branch before executing these commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment