I have deleted my git commit history plenty of times just to make my repository look "clean" (roast me in the comments for it). It's probably best to not do this but I will still share how to do it.
Delete entire commit history
git checkout --orphan latest_branch
git add -A
git commit -am "commit message"
git branch -D main
git branch -m main
git push -f origin main
I did not figure this out myself or anything. I got it from here. It's by Desta Haileselassie Hagos, later edited by creyD
Personally, I don't like to type out every single one of those commands. So, I made a Git alias that allows me to do all of that in one single command. Using my Git alias the command becomes:
git renew "sub to axorax"
To make the Git alias for yourself, paste the command below in the terminal:
git config --global alias.renew '!f() { \
git checkout --orphan latest_branch && \
git add -A && \
git commit -am "$1" && \
git branch -D main && \
git branch -m main && \
git push -f origin main; \
}; f'
Top comments (0)