Occasionally, the time comes to open source a piece of a project you are working on. If you’ve been using Git, and been working on it for more than a day with more than one person, then you probably have a nice commit history to your project.
This history is important and useful to your team, but probably not something you want to share with the world. Additionally, if you are only sharing out a part of the project, then putting out your entire commit history defeats the point. But you also end defeating the purpose of version control if you build out a separate body of code held in a different repo, particularly if you expect you will be contributing additional features to the open sourced component down the road.
So how do you make a branch with a clean, empty commit history?
checkout --orphan, the nice and easy way to add a new, detached head to your repo. It’s purpose, as described by the doc, is exactly for this situation:
You might want to do this to publish an open source branch of a project whose current tree is “clean”, but whose full history contains proprietary or otherwise encumbered bits of code.
All that is required is entering:
'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
I recommend reading over the spec before running it, but it goes down fairly smooth.
If you prefer to work out of SourceTree, you run the slightly shorter statement of:
git checkout --orphan <new_branch>