Skip to content

Instantly share code, notes, and snippets.

@stdrc
Last active October 18, 2025 06:06
Show Gist options
  • Select an option

  • Save stdrc/1994e21019d25fb10bcd1983415882b1 to your computer and use it in GitHub Desktop.

Select an option

Save stdrc/1994e21019d25fb10bcd1983415882b1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
# Git Worktree Manager
dir_name=$(basename "$(pwd)")
worktrees_dir=$(pwd)/../$dir_name.worktrees
list() {
git worktree list "$@"
}
new() {
local branch_name=$1
shift
mkdir -p "$worktrees_dir"
git worktree add -b "$branch_name" "$worktrees_dir/$branch_name" "$@"
}
delete() {
local branch_name=$1
shift
git worktree remove "$worktrees_dir/$branch_name" "$@"
}
open() {
local branch_name=$1
cursor "$worktrees_dir/$branch_name"
}
# Command alias mapping
case "${1:-}" in
ls)
shift
list "$@"
;;
del|remove|rm)
shift
delete "$@"
;;
add)
shift
new "$@"
;;
list|new|delete|open)
"$@"
;;
*)
echo "Usage: wt [list|new|delete|open] [args...]"
echo ""
echo "Commands:"
echo " list List all worktrees"
echo " new <branch> Create new worktree with branch"
echo " delete <branch> Delete worktree"
echo " open <branch> Open worktree in Cursor"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment