Created
December 28, 2025 18:16
-
Star
(100)
You must be signed in to star a gist -
Fork
(19)
You must be signed in to fork a gist
-
-
Save dhh/18575558fc5ee10f15b6cd3e108ed844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a new worktree and branch from within current git directory. | |
| ga() { | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: ga [branch name]" | |
| exit 1 | |
| fi | |
| local branch="$1" | |
| local base="$(basename "$PWD")" | |
| local path="../${base}--${branch}" | |
| git worktree add -b "$branch" "$path" | |
| mise trust "$path" | |
| cd "$path" | |
| } | |
| # Remove worktree and branch from within active worktree directory. | |
| gd() { | |
| if gum confirm "Remove worktree and branch?"; then | |
| local cwd base branch root | |
| cwd="$(pwd)" | |
| worktree="$(basename "$cwd")" | |
| # split on first `--` | |
| root="${worktree%%--*}" | |
| branch="${worktree#*--}" | |
| # Protect against accidentially nuking a non-worktree directory | |
| if [[ "$root" != "$worktree" ]]; then | |
| cd "../$root" | |
| git worktree remove "$worktree" --force | |
| git branch -D "$branch" | |
| fi | |
| fi | |
| } |
ga should return 1 instead of exit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In zsh the
local pathwill mess up the path andgitwill probably fail withzsh: command not found: git.Changing
pathtoworktree_pathfixes it.