Skip to content

Instantly share code, notes, and snippets.

@wojas
Created May 24, 2019 13:22
Show Gist options
  • Save wojas/14bd28db35ec87b6e031a5f48ad48f9a to your computer and use it in GitHub Desktop.
Save wojas/14bd28db35ec87b6e031a5f48ad48f9a to your computer and use it in GitHub Desktop.
Script to visually select a recent git branch to switch to
#!/bin/bash
# Script to visually select a recent git branch to switch to
# Requires https://github.com/junegunn/fzf (brew install fzf)
branches () {
git for-each-ref --sort=-committerdate refs/heads/ | sed 's|.*refs/heads/||' | head -30
}
branch=$(branches | fzf --no-sort --layout=reverse)
set -ex
git checkout "$branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment