Skip to content

Instantly share code, notes, and snippets.

@AliciaMoses
Last active August 22, 2024 21:12
Show Gist options
  • Save AliciaMoses/39293e2e9e9eeafab4e27cb0821cec60 to your computer and use it in GitHub Desktop.
Save AliciaMoses/39293e2e9e9eeafab4e27cb0821cec60 to your computer and use it in GitHub Desktop.
fzf + `git checkout`
function gxo() {
local branches branch
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)') || return
# Add a separator and then list all branches
branches="$branches"$'\n'"$(git branch --all | grep -v '\->' | sed 's/^[* ]*//')" || return
# Use fzf to select a branch + added useless but cool looking graph
branch=$(echo "$branches" | fzf --height 40% --border --preview 'git log --oneline --graph --decorate --color=always {}') || return
git checkout $(echo "$branch" | sed 's#^remotes/[^/]*/##')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment