Skip to content

Instantly share code, notes, and snippets.

@Plaenkler
Forked from heiswayi/repo-reset.md
Last active December 28, 2023 11:48
Show Gist options
  • Save Plaenkler/22a76cf4ed554e3d7ac6d31e70b9889e to your computer and use it in GitHub Desktop.
Save Plaenkler/22a76cf4ed554e3d7ac6d31e70b9889e to your computer and use it in GitHub Desktop.
Git - reset/delete commit history of your repository

Challenge

Delete all commits and keep the code in its current state.

Solution

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "[INIT] Initial commit"

# Delete the old branch:
git branch -D main

# Rename the temporary branch to main:
git branch -m main

# Finally, force update to our repository:
git push -f origin main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment