Git clean up commit history

I had to clean up 3 years worth of commit history today and rebasing was a royal pain as there were alot of merge conflicts to manually resolve. I opted to have a new branch that was clean of commit history in order to start fresh (without losing old history as they still exist on the old branches). Here’s what I needed in point form:

* first commit must be empty (master branch’s first commit was not empty)
* all changes from first commit till the last needs to be wrapped into one commit
* ability to switch from old branch with lots of history and new branch with condensed history.

NOTE: This does not make the repos clean of unwanted files/history. Please followup on this post on details how to do that: https://help.github.com/articles/remove-sensitive-data/


git checkout the_original_branch
git checkout --orphan new_branch
git rm -rf .
git commit --allow-empty -m 'empty commit'
git merge --squash the_original_branch
git commit -m "1 commit to get to branch: the_original_branch"

pushing this branch to your main repo:


git push

You may now download that specific branch and it will have a simplified commit history on another location


git clone -b new_branch ssh://git/location.git