gx retarget moves a branch from one parent to another using git rebase --onto, updates the stack config, pushes the result, and optionally retargets the GitHub PR.
Usage
Arguments
| Argument | Description |
|---|---|
branch | Branch to retarget (default: current branch) |
new-target | New base branch to rebase onto |
Flags
| Flag | Description |
|---|---|
--dry-run | Show what would happen without making changes |
What Happens
- Fetches the latest from remote
- Rebases the branch onto the new target using
git rebase --onto origin/<new-target> <old-parent-head> <branch> - Pushes with
--force-with-lease - Updates the stack config to record the new parent
- Retargets the PR via
gh pr edit <branch> --base <new-target>(ifghis available)
Examples
Auto PR Retarget
If the GitHub CLI (gh) is installed and authenticated, gx automatically runs:
OK PR for <branch> automatically retargeted to <new-target>. If it fails (no PR exists, or gh is not available), gx prints a reminder: WARN Remember to retarget the PR for <branch> to <new-target>.
Conflict Handling
If a rebase conflict occurs during retargeting:Details
Details
- If the branch is already based on the new target, gx prints
> <branch> is already based on <target>. Nothing to do. - If no saved parent exists in the stack config, gx falls back to using the merge base and prints a warning
- The rebase uses
origin/<new-target>when the remote branch exists, ensuring you rebase onto the latest remote state - Uses the stored
parent_headSHA as the old base for--onto, which is more reliable than using the branch name when branches have been rebased