Skip to content

Instantly share code, notes, and snippets.

@mikiyaf
Created November 13, 2017 01:13
Show Gist options
  • Save mikiyaf/f20ff73994adef2e743f9ee39f20c319 to your computer and use it in GitHub Desktop.
Save mikiyaf/f20ff73994adef2e743f9ee39f20c319 to your computer and use it in GitHub Desktop.
fco - checkout git branch/tag
fco() {
local tags branches target
tags=$(
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
branches=$(
git branch --all | grep -v HEAD |
sed "s/.* //" | sed "s#remotes/[^/]*/##" |
sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
target=$(
(echo "$tags"; echo "$branches") |
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return
git checkout $(echo "$target" | awk '{print $2}')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment