Why would I do that?
To be really honest, I don’t know. But, I found myself in a situation that all my old commits on this blog repo where kinda ankward mostly because I was really unexperient at web development (not saying that I’ve improved that much). Without further ado, let’s go!
-
Checkout to another orphan branch;
git checkout --orphan branch_copy
-
Add all the files to this specific branch tracking;
git add -A
-
Commit the files added;
git commit -am "re-start!"
-
Delete the old branch;
git branch -D master/main
-
Rename the current branch;
git branch -m main/master
-
To finish, force-update your repo.
git push -f origin main/master (depending on the name you put earlier)
By doing this all your old commit history will disappear from history.
Simple as it is, you just “cleaned” your commit history! Hope it helped.