Last Updated: February 25, 2016
· aebsr

Git Checkout Orphan

This little alias will automate git checkout of orphan branches as well as:

  • remove the previous branches' contents
  • add a README.md and commit it (for future use & to avoid an empty commit)
  • and lastly push your new branch to git and set the upstream
coo() {
    if [ $1 ]; then
        git checkout --orphan $1;
        git rm -rf .;
        touch README.md;
        git add README.md;
        git commit -m 'orphan branch initial commit';
        git push --set-upstream origin $1;

usage, without the $: $ coo new-branch-name

Now at any point in a project you can start fresh with a clean branch. I tend to use this when prototyping or doing a complete rewrite.

Caveat: Orphan branches can't be (reasonably) merged, though that's kind of the point. via @lettertwo

Say Thanks
Filed Under

Awesome Job

Bc0a6794 05ee 11e8 902a 778405599bdb
Software Engineer
Denver, San Francisco
Full Time