gx parent prints the parent branch of the current branch and exits. It is designed for use in shell scripts and pipelines — it outputs only the branch name with no decoration.
Usage
Behavior
- If the current branch is in the stack, prints the stack parent
- If the current branch is not in the stack, prints the HEAD branch (main/master)
- If you are on trunk, exits with code 1 (no output)
- If not in a git repo, exits with code 1 (no output)
Examples
Composability
gx parent is designed for shell pipelines and scripting:
gx parent uses exit codes for scripting: exit 0 means a parent was found and printed, exit 1 means no parent (on trunk, detached HEAD, or not in a repo). It never prints error messages to stdout.Details
Details
- Output is a single line with just the branch name, no color codes or prefix
- When the branch is in the stack config, the recorded parent is used
- When the branch is not in the stack, the HEAD branch is returned as a sensible default
- On trunk, there is no parent, so the command exits with code 1 and no output