Skip to content

Instantly share code, notes, and snippets.

@withakay
Created August 19, 2025 14:56
Show Gist options
  • Save withakay/dec184e9a0a5111b929e6ad8f0399d04 to your computer and use it in GitHub Desktop.
Save withakay/dec184e9a0a5111b929e6ad8f0399d04 to your computer and use it in GitHub Desktop.
Switch git work trees interactively with fzf
# include this in your .bash_profile or .zshrc or similar
# Note: you can't put this in script and call it as `cd` will only affect
# the subshell the script runs in
function wtcd () {
local dir
dir=$(git wtl --porcelain | grep "^worktree" | awk '{print $2}'| fzf \
--height=40% \
--layout=reverse \
--border \
--prompt="Select worktree: " \
--preview="echo {} | awk '{print \$1}' | xargs ls -la 2>/dev/null | head -20" \
--preview-window=right:50%:wrap) && cd "$dir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment