Monthly Archives: June 2019

Git: cleaning a branch before a PR, and merge back the clean history to the messy WIP branch

Sometimes, I have a branch with a new feature I work on, call it Feature_mess.

At some point I want to show this feature to colleagues, so I want to have a clean history, and remove some WIP stuff

To this end :

git checkout Feature_mess
git checkout -b Feature_clean
git rebase -i Feature_clean master (or whatever base you want)

Cleanup history here, remove crappy things, merge a lot of commits, rewrite history !
Now to benefit from this clean history as a base of Feature_mess

git branch temp Feature_mess
git checkout temp
git reset --soft Feature_clean

Now you are in the state of mess, with the history of cleanup, you can check diff and then

git commit

Et voilĂ  !

More information on git reset here : https://gist.github.com/tnguyen14/0827ae6eefdff39e452b