Skip to content

Instantly share code, notes, and snippets.

@Brantron
Created September 4, 2018 20:23
Show Gist options
  • Save Brantron/1bd191d3bddd9107c2ce8370f7e330ae to your computer and use it in GitHub Desktop.
Save Brantron/1bd191d3bddd9107c2ce8370f7e330ae to your computer and use it in GitHub Desktop.
an interactive git branch selector for fzf
alias branchlist="git for-each-ref --sort='-authordate' --format='%1B[0;34m%(refname:short)%1B[m ===> %1B[1;35m%(subject)' refs/heads | sed -e 's-refs/heads/--'"
function branches() {
local branch_name=$(branchlist | fzf --ansi -m)
if [[ $branch_name ]]; then
echo $branch_name | awk '{print $1}' | xargs git co
fi
}
@Brantron
Copy link
Author

Brantron commented Aug 25, 2020

@chrisMYchen ensure you have fzf installed and globally available. Also you will need a git alias for co if not change line 6 to echo $branch_name | awk '{print $1}' | xargs git checkout

Does that help?

@chrisMYchen
Copy link

Perfect! Just missed the co alias setup! This is excellent :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment