Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ git gtr ai my-feature # Start claude
git gtr run my-feature npm test # Run tests

# Navigate to worktree
gtr new my-feature --cd # Create and cd (requires shell integration)
gtr cd # Interactive picker (requires fzf + shell integration)
gtr cd my-feature # Requires shell integration (see below)
cd "$(git gtr go my-feature)" # Alternative without shell integration
Expand Down Expand Up @@ -230,6 +231,7 @@ test -f "$_gtr_init"; or git gtr init fish >/dev/null 2>&1
source "$_gtr_init" 2>/dev/null

# Then navigate with:
gtr new my-feature --cd # Create and land in the new worktree
gtr cd # Interactive worktree picker (requires fzf)
gtr cd my-feature
gtr cd 1
Expand Down Expand Up @@ -360,7 +362,7 @@ git gtr config add gtr.copy.include "**/.env.example"
# Run setup after creating worktrees
git gtr config add gtr.hook.postCreate "npm install"

# Re-source environment after gtr cd (runs in current shell)
# Re-source environment after gtr cd or gtr new --cd (runs in current shell)
git gtr config add gtr.hook.postCd "source ./vars.sh"

# Disable color output (or use "always" to force it)
Expand Down
6 changes: 3 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ git gtr config add gtr.hook.preRemove "npm run cleanup"
# Post-remove hooks
git gtr config add gtr.hook.postRemove "echo 'Cleaned up!'"

# Post-cd hooks (run after gtr cd, in current shell)
# Post-cd hooks (run after gtr cd or gtr new --cd, in current shell)
git gtr config add gtr.hook.postCd "source ./vars.sh"
```

Expand All @@ -306,11 +306,11 @@ git gtr config add gtr.hook.postCd "source ./vars.sh"
| `postCreate` | After worktree creation | Setup, install dependencies |
| `preRemove` | Before worktree deletion | Cleanup requiring directory access |
| `postRemove` | After worktree deletion | Notifications, logging |
| `postCd` | After `gtr cd` changes directory | Re-source environment, update shell context |
| `postCd` | After `gtr cd` or `gtr new --cd` changes directory | Re-source environment, update shell context |

> **Note:** Pre-remove hooks abort removal on failure. Use `--force` to skip failed hooks.
>
> **Note:** `postCd` hooks run in the **current shell** (not a subshell) so they can modify environment variables. They only run via `gtr cd` (shell integration), not `git gtr go`. Failures warn but don't undo the `cd`.
> **Note:** `postCd` hooks run in the **current shell** (not a subshell) so they can modify environment variables. They only run via shell integration (`gtr cd`, `gtr new --cd`), not raw `git gtr` commands or `git gtr go`. Failures warn but don't undo the directory change.

**Environment variables available in hooks:**

Expand Down
9 changes: 6 additions & 3 deletions lib/commands/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ git gtr init - Generate shell integration
Usage: git gtr init <shell> [--as <name>]

Generates shell functions for enhanced features like 'gtr cd <branch>'
which changes directory to a worktree. Add to your shell configuration.
and 'gtr new <branch> --cd', which can change the current shell directory.
Add to your shell configuration.

Output is cached to ~/.cache/gtr/ for fast shell startup (~1ms vs ~60ms).
The cache refreshes the next time 'git gtr init <shell>' runs (checks version).
Expand Down Expand Up @@ -377,6 +378,7 @@ Setup (sources cached output directly for fast startup):
eval "$(git gtr init zsh --as gwtr)"

After setup:
gtr new my-feature --cd # create and cd into worktree
gtr cd my-feature # cd to worktree
gtr cd 1 # cd to main repo
gtr cd # interactive picker (requires fzf)
Expand Down Expand Up @@ -568,7 +570,7 @@ SETUP & MAINTENANCE:
Usage: eval "$(git gtr completion zsh)"

init <shell> [--as <name>]
Generate shell integration for cd support (bash, zsh, fish)
Generate shell integration for gtr cd and gtr new --cd (bash, zsh, fish)
--as <name>: custom function name (default: gtr)
Output is cached for fast startup (refreshes when 'git gtr init' runs)
See git gtr help init for recommended setup
Expand Down Expand Up @@ -596,6 +598,7 @@ WORKFLOW EXAMPLES:
git gtr run feature/user-auth npm run dev # Start dev server

# Navigate to worktree directory
gtr new hotfix --cd # Create and cd into worktree (with shell integration)
gtr cd # Interactive picker (requires fzf)
gtr cd feature/user-auth # With shell integration (git gtr init)
cd "$(git gtr go feature/user-auth)" # Without shell integration
Expand Down Expand Up @@ -646,7 +649,7 @@ CONFIGURATION OPTIONS:
gtr.hook.postCreate Post-create hooks (multi-valued)
gtr.hook.preRemove Pre-remove hooks (multi-valued, abort on failure)
gtr.hook.postRemove Post-remove hooks (multi-valued)
gtr.hook.postCd Post-cd hooks (multi-valued, shell integration only)
gtr.hook.postCd Post-cd hooks (multi-valued, gtr cd / gtr new --cd only)
gtr.ui.color Color output mode (auto, always, never; default: auto)

────────────────────────────────────────────────────────────────────────────────
Expand Down
Loading