|
| 1 | +# gh-stack autorebase |
| 2 | + |
| 3 | +Rebuild and push an entire stack after local changes. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```bash |
| 8 | +gh-stack autorebase 'STACK-ID' -C /path/to/repo |
| 9 | +gh-stack autorebase 'STACK-ID' -C /path/to/repo --ci # skip confirmation |
| 10 | +gh-stack autorebase 'STACK-ID' -C /path/to/repo -b <sha> # cherry-pick boundary |
| 11 | +``` |
| 12 | + |
| 13 | +## How it works |
| 14 | + |
| 15 | +1. Checks out the base branch (e.g., `main`) |
| 16 | +2. Cherry-picks commits from each PR in stack order |
| 17 | +3. Updates local branches to point at new commits |
| 18 | +4. Force-pushes all branches at once |
| 19 | + |
| 20 | +This reconstructs a clean, linear stack from your local changes. |
| 21 | + |
| 22 | +## Flags |
| 23 | + |
| 24 | +| Flag | Description | |
| 25 | +|------|-------------| |
| 26 | +| `-C`, `--project` | Path to local repository (required) | |
| 27 | +| `--ci` | Skip confirmation prompt | |
| 28 | +| `-b`, `--initial-cherry-pick-boundary` | Stop initial cherry-pick at this SHA | |
| 29 | +| `-o`, `--origin` | Git remote name (default: origin) | |
| 30 | +| `-r`, `--repository` | Override repository (owner/repo) | |
| 31 | +| `-e`, `--excl` | Exclude PR by number (repeatable) | |
| 32 | + |
| 33 | +## Conflict handling |
| 34 | + |
| 35 | +If a conflict occurs during cherry-picking: |
| 36 | + |
| 37 | +1. The process pauses |
| 38 | +2. Resolve conflicts manually |
| 39 | +3. Stage resolved files with `git add` |
| 40 | +4. Continue with `git cherry-pick --continue` |
| 41 | + |
| 42 | +## Example |
| 43 | + |
| 44 | +After amending a commit in the middle of your stack: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Your local history diverged from remote |
| 48 | +git checkout feat/part-1 |
| 49 | +git commit --amend -m "Updated message" |
| 50 | + |
| 51 | +# Rebuild and sync the entire stack |
| 52 | +gh-stack autorebase 'STACK-ID' -C . |
| 53 | +``` |
| 54 | + |
| 55 | +## Warnings |
| 56 | + |
| 57 | +- **Force-pushes** to all branches in the stack |
| 58 | +- Back up your work before running |
| 59 | +- Collaborators will need to reset their local branches |
| 60 | + |
| 61 | +## When to use |
| 62 | + |
| 63 | +- After amending commits |
| 64 | +- After interactive rebase |
| 65 | +- After resolving conflicts with upstream |
| 66 | +- After reordering commits |
| 67 | + |
| 68 | +## See also |
| 69 | + |
| 70 | +- [log](log.md) - Verify stack structure after rebase |
| 71 | +- [rebase](rebase.md) - Generate a rebase script for manual control |
0 commit comments