|
1 | 1 | # git-stack |
2 | 2 |
|
3 | | -`git-stack` is a command-line tool for managing stacked git branches — a workflow where you develop |
4 | | -features atop one another, keeping their history clean and rebasing as needed. It tracks |
5 | | -relationships between branches, helps you re-stack and synchronize them, and visualizes your stack |
6 | | -tree. |
7 | | - |
8 | | -`git-stack` also allows for synchronization between Github and local state. |
9 | | - |
10 | | -## Key Features |
11 | | - |
12 | | -- Stacked Workflow: Track parent-child branch relationships ("stacks") in your repo. |
13 | | -- Restack: Automatically rebase your branch stack on top of trunk or another branch. |
14 | | -- Status Tree: Visualize your current stacked branches, their hierarchy, and sync status. |
15 | | -- Branch Mounting: Change the parent branch of an existing branch in your stack. |
16 | | -- Diffs: Show changes between a branch and its parent. |
17 | | -- Safe Operations: Prevent accidental data loss by checking upstream sync status. |
| 3 | +A command-line tool for managing stacked git branches. Develop features on top of one another, keep history clean, and sync with GitHub. |
18 | 4 |
|
19 | 5 | ## Installation |
20 | 6 |
|
21 | | -Build from source (Rust required): |
22 | | - |
23 | 7 | ```bash |
24 | | -cargo install --path . |
| 8 | +cargo install --git https://github.com/wbbradley/git-stack --locked |
25 | 9 | ``` |
26 | 10 |
|
27 | | -This will install a CLI you can use as follows: |
| 11 | +## Quick Start |
28 | 12 |
|
29 | 13 | ```bash |
30 | | -git stack <command> [options] |
| 14 | +git stack # show your stack |
| 15 | +git stack sync # sync local state with GitHub (push + pull) |
| 16 | +git stack checkout feature # create branch "feature" as child of current branch |
| 17 | +# ...make changes, commit... |
| 18 | +git stack restack # restack the current branch onto its parent |
| 19 | +git stack diff # diff against parent branch |
| 20 | +git stack pr create # create GitHub PR with correct base branch |
31 | 21 | ``` |
32 | 22 |
|
33 | | -## Usage |
| 23 | +## Commands |
34 | 24 |
|
35 | | -You can invoke `git-stack` directly or as a git subcommand: |
| 25 | +### View Your Stack |
36 | 26 |
|
37 | 27 | ```bash |
38 | | -git stack <subcommand> [options] |
| 28 | +git stack # show the stack tree (alias: git stack status) |
39 | 29 | ``` |
40 | 30 |
|
41 | | -### Common Subcommands |
42 | | - |
43 | | -- `status`: Show the current stack tree in the repo. |
44 | | - - _Default_, so `git stack` is equivalent to `git stack status`. |
45 | | - |
46 | | -- `checkout <branch>`: Create a new branch stacked on the current branch, or checkout an existing |
47 | | - one in the stack. |
48 | | - |
49 | | -- `restack [--branch <branch>]`: Rebase the named (or current) branch and its descendents onto their |
50 | | - updated stack base (like trunk or a parent feature branch). This command recursively applies to |
51 | | - all ancestors of the given branch. |
| 31 | +### Create Branches |
52 | 32 |
|
53 | | -- `mount [<parent-branch>]`: Mounts (attaches) the current branch on a different parent branch. |
| 33 | +```bash |
| 34 | +git stack checkout feature # create "feature" stacked on current branch |
| 35 | +``` |
54 | 36 |
|
55 | | -- `diff [<branch>]`: Show diff between a branch and its stack parent. |
| 37 | +### Restack Branches |
56 | 38 |
|
57 | | -- `delete <branch>`: Remove a branch from the stack tree. |
| 39 | +```bash |
| 40 | +git stack restack # restack current branch onto its parent |
| 41 | +git stack restack -afp # fetch, recursively restack from trunk, push on success |
| 42 | +``` |
58 | 43 |
|
59 | | -### Examples |
| 44 | +The `-afp` flags: |
| 45 | +- `-a` / `--ancestors`: recursively restack all ancestors from trunk up to current branch |
| 46 | +- `-f` / `--fetch`: fetch updates from remote first |
| 47 | +- `-p` / `--push`: push branch updates to remote on success |
60 | 48 |
|
61 | | -#### See your stack status |
| 49 | +### Diff Against Parent |
62 | 50 |
|
63 | | -``` |
64 | | -git stack status |
| 51 | +```bash |
| 52 | +git stack diff # diff against parent branch |
65 | 53 | ``` |
66 | 54 |
|
67 | | -#### Create and stack a new branch |
| 55 | +### Create Pull Requests |
68 | 56 |
|
69 | | -``` |
70 | | -git stack checkout my-feature |
| 57 | +```bash |
| 58 | +git stack pr create # create GitHub PR with correct base branch |
71 | 59 | ``` |
72 | 60 |
|
73 | | -#### Restack your current branch |
| 61 | +### Change Parent Branch |
74 | 62 |
|
75 | | -``` |
76 | | -git stack restack |
| 63 | +```bash |
| 64 | +git stack mount <parent> # stack current branch on a different parent |
77 | 65 | ``` |
78 | 66 |
|
79 | | -#### Change the parent stack of a feature branch |
| 67 | +This only updates git-stack metadata, not git history. Use `restack` afterward to keep this branch |
| 68 | +in sync with its parent. |
80 | 69 |
|
81 | | -``` |
82 | | -git stack mount new-parent-branch |
| 70 | +### Delete Branches |
| 71 | + |
| 72 | +```bash |
| 73 | +git stack delete <branch> # remove a branch from the stack |
83 | 74 | ``` |
84 | 75 |
|
85 | | -#### Show diff with parent |
| 76 | +Note that `git stack sync` will automatically prune local branches that are duplicates of the remote |
| 77 | +branch, or have already been merged. |
86 | 78 |
|
87 | | -``` |
88 | | -git stack diff my-feature |
89 | | -``` |
| 79 | +## Workflow Example |
90 | 80 |
|
91 | | -#### Remove a branch from stack management |
| 81 | +```bash |
| 82 | +# Start on main |
| 83 | +git stack checkout auth # create auth branch |
| 84 | +# ...implement auth, commit... |
92 | 85 |
|
93 | | -``` |
94 | | -git stack delete my-feature |
| 86 | +git stack checkout login # create login branch (child of auth) |
| 87 | +# ...implement login, commit... |
| 88 | + |
| 89 | +git stack # see your stack tree |
| 90 | +git stack restack -afp # sync everything and push |
| 91 | +git stack pr create # create PR for current branch |
95 | 92 | ``` |
96 | 93 |
|
97 | 94 | ## Stack Storage |
98 | 95 |
|
99 | | -- Stack state is stored per-repo in a YAML file at: |
100 | | - `~/.local/state/git-stack/state.yaml` (using XDG state dir conventions). |
101 | | - |
102 | | -## Requirements |
103 | | - |
104 | | -- A POSIX shell |
105 | | -- git (on your `$PATH`) |
106 | | -- Rust (to install/build) |
| 96 | +Stack state is stored per-repo in `~/.local/state/git-stack/state.yaml`. |
107 | 97 |
|
108 | 98 | ## Troubleshooting |
109 | 99 |
|
110 | | -If `git stack` reports missing branches or refuses to restack: |
| 100 | +If `git stack` reports issues: |
111 | 101 |
|
112 | | -- Ensure your working tree is clean (`git status`). |
113 | | -- Use standard git commands to resolve any rebase conflicts (`git mergetool` is your friend, |
114 | | - followed by `git rebase --continue`), then rerun `git stack restack`. |
115 | | -- Note that the last-known-good location of the parent branch is stored in the sub-branch in order |
116 | | - to allow for cleaner movement of branches |
| 102 | +- Ensure your working tree is clean (`git status`) |
| 103 | +- Resolve rebase conflicts with standard git commands (`git mergetool`, then `git rebase --continue`) |
| 104 | +- Rerun `git stack restack` after resolving conflicts |
117 | 105 |
|
118 | 106 | ## License |
119 | 107 |
|
|
0 commit comments