Skip to content

Instantly share code, notes, and snippets.

@fsimonis
Created May 5, 2023 10:49
Show Gist options
  • Save fsimonis/e3e76c2bab24d3f3032cbcbd918e5f33 to your computer and use it in GitHub Desktop.
Save fsimonis/e3e76c2bab24d3f3032cbcbd918e5f33 to your computer and use it in GitHub Desktop.
A bash script to change between git worktrees in a terminal using fzf.
changeworktree()
{
WT=$(git worktree list --porcelain | sed -e "/^HEAD/d" -e "/^$/d" -e "s/^worktree //" -e "s/branch refs\/heads\/\(.\+\)/\1/" | paste -d '\t' - - | column -t --output-separator=$'\t' | fzf --ansi | cut -f1 -d' ' )
[ -n "$WT" ] && cd $WT
}
alias cdgw="changeworktree"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment