Article Thumbnail

How to delete entire git commit history?

Axorax
1 min readJul 26, 2024

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'

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Axorax
Axorax

Written by Axorax

0 Followers

Hey! I like coding and tech

No responses yet

Write a response