Last active
September 20, 2016 19:42
-
-
Save dsilfen-handy/b3fbb074718d1ac59974146bd9ee2130 to your computer and use it in GitHub Desktop.
small shell script to quickly switch branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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