Skip to content

Instantly share code, notes, and snippets.

@dsilfen-handy
Last active September 20, 2016 19:42
Show Gist options
  • Save dsilfen-handy/b3fbb074718d1ac59974146bd9ee2130 to your computer and use it in GitHub Desktop.
Save dsilfen-handy/b3fbb074718d1ac59974146bd9ee2130 to your computer and use it in GitHub Desktop.
small shell script to quickly switch branches
CURRENT_BRANCH=$(git describe --contains --all HEAD)
PREVIOUS_BRANCH=$(git for-each-ref --sort=committerdate refs/heads/ | tail -n 1 | cut -c 60-)
TWO_BACK_BRANCH=$(git for-each-ref --sort=committerdate refs/heads/ | tail -n 2 | head -n 1 | cut -c 60-)
if [[ $CURRENT_BRANCH == $PREVIOUS_BRANCH ]]; then
GITCOMMAND="git checkout ${TWO_BACK_BRANCH}"
else
GITCOMMAND="git checkout ${PREVIOUS_BRANCH}"
fi
eval $GITCOMMAND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment