Skip to content

Instantly share code, notes, and snippets.

@natecavanaugh
Created November 16, 2011 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natecavanaugh/1371809 to your computer and use it in GitHub Desktop.
Save natecavanaugh/1371809 to your computer and use it in GitHub Desktop.
Alias for 'git split'
# Paste this line into your .gitconfig
split = "!f() { git checkout -b $2 && msg=$(git stash save) && git checkout - && git reset --hard $1 && git checkout $2 && [[ ! $msg =~ ^'No local changes to save'$ ]] && git stash pop; }; f"
# move all commits after the SHA to a new branch
# use case: I accidentally make a bunch of commits into my master branch for a specific feature.
# I want to split off a feature branch and reset my current branch to some point in time before my changes.
# usage
# git split SHA NEW_BRANCH_NAME
# examples.
# git split origin/master history-support
# git split 5c29ab4 iframe-experiment
# stashes any changes you may have uncommitted in the branch as well and applies them in the new branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment