This command is for use inside a worktree created by a
git worktree add workflow. It merges the PR, returns to
the main repo, and removes the worktree.
Steps
- •
Detect the current branch name. Abort if on
mainormaster. - •
Determine the worktree root and the main repo root:
codegit worktree list
Abort if not inside a secondary worktree.
- •
Gather PR and issue info before merging:
codegh pr view --json number,title,url,reviews, statusCheckRollup,additions,deletions,changedFiles
Abort if no PR exists for this branch.
- •
If the branch name matches
issue-<N>, also fetch:codegh issue view <N> --json title,body,url
- •
Merge the PR (squash by default):
codegh pr merge --squash --delete-branch
- •
Change directory to the main repo root.
- •
Pull latest main:
codegit pull --ff-only
- •
Remove the worktree:
codegit worktree remove <worktree-path> git worktree prune
- •
Delete the local branch if it still exists:
codegit branch -d <branch>
- •
If running inside tmux, rename the window:
codecommand tmux rename-window "ready"
- •
Print the completion summary:
code═══ Merge Complete ═════════════════════════════ Issue: #<N> — <issue title> <issue URL> <first 2-3 lines of issue body, trimmed> PR: #<M> — <PR title> <PR URL> Diff: <changedFiles> files (+<additions> -<deletions>) Method: Squash Checks: ✓ all passed | ✗ <N> failed (list names) Reviews: <reviewer names and status, e.g. "alex ✓"> Cleanup: Worktree removed, branch deleted ════════════════════════════════════════════════Omit the Issue section if the branch doesn't match an issue pattern or the issue lookup fails.
Important
- •Confirm with the user before running
gh pr merge. - •If merge fails (e.g. checks not passing), stop and report the error — do NOT force merge.