Skip to content

Add shell helper for easier worktree directory switching #97

@echarrod

Description

@echarrod

Problem

Switching to a worktree directory currently requires a verbose subshell pattern:

cd "$(git gtr go feature/user-auth)"

This is cumbersome for frequent use.

Proposal

Provide a built-in shell helper (e.g. a function or alias) that allows something like:

gtr cd feature/user-auth

Why not git gtr cd?

Since git gtr runs as a subprocess, it cannot change the parent shell's working directory. A true cd command would need to be implemented as a shell function rather than a script command.

Possible approaches

  1. Ship a shell function that users source in their shell profile (.bashrc/.zshrc/config.fish), e.g.:

    gtr() {
      if [ "$1" = "cd" ]; then
        shift
        local dir
        dir="$(git gtr go "$@")" && cd "$dir"
      else
        command git gtr "$@"
      fi
    }
  2. Add a git gtr shell-helper command that prints the function definition so users can eval/source it:

    # In .bashrc/.zshrc:
    eval "$(git gtr shell-helper bash)"

    Similar to how tools like direnv, fnm, and zoxide handle shell integration.

  3. Document a recommended alias in the README, e.g.:

    alias gcd='cd "$(git gtr go"'

Option 2 feels most aligned with the project's existing patterns (similar to git gtr completion).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions