opencode-gitbutler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,512 @@
1
+ # GitButler CLI Workflow Examples
2
+
3
+ Real-world examples of common workflows.
4
+
5
+ ## Example 1: Starting Independent Parallel Work
6
+
7
+ **Scenario:** Need to work on two independent features: a new API endpoint and UI styling updates.
8
+
9
+ ```bash
10
+ # 1. Check current state
11
+ but status --json
12
+
13
+ # 2. Create two independent (parallel) branches
14
+ but branch new api-endpoint
15
+ but branch new ui-styling
16
+
17
+ # 3. Make changes to multiple files
18
+ # (edit api/users.js and components/Button.svelte)
19
+
20
+ # 4. Check what's unstaged
21
+ but status --json
22
+
23
+ # 5. Stage files to appropriate branches
24
+ but stage a1 bu # api/users.js → api-endpoint branch
25
+ but stage a2 bv # Button.svelte → ui-styling branch
26
+
27
+ # 6. Commit each branch (--only to commit only staged files)
28
+ but commit bu --only -m "Add user details endpoint"
29
+ but commit bv --only -m "Update button hover styles"
30
+
31
+ # 7. Push branches independently (optional, can skip if using pr new)
32
+ but push bu
33
+ but push bv
34
+
35
+ # 8. Create pull requests (auto-pushes if not already pushed)
36
+ but pr new bu
37
+ but pr new bv
38
+ ```
39
+
40
+ **Why parallel branches?** The API endpoint and UI styling are independent - neither depends on the other. They can be reviewed and merged separately.
41
+
42
+ ## Example 2: Building Stacked Features
43
+
44
+ **Scenario:** Need to add authentication, then build a user profile page that requires auth.
45
+
46
+ ```bash
47
+ # 1. Check current state and update
48
+ but pull
49
+ but status --json
50
+
51
+ # 2. Create base branch for authentication
52
+ but branch new add-authentication
53
+
54
+ # 3. Implement auth and commit
55
+ # (edit auth/login.js, auth/middleware.js)
56
+ but status --json
57
+ but stage <file-ids> bu # Stage changes to auth branch
58
+ but commit bu --only -m "Add JWT authentication"
59
+
60
+ # 4. Create stacked branch anchored on authentication
61
+ but branch new user-profile -a bu
62
+
63
+ # 5. Implement profile page (depends on auth)
64
+ # (edit pages/profile.js)
65
+ but status --json
66
+ but stage <file-ids> bv # Stage changes to profile branch
67
+ but commit bv --only -m "Add user profile page"
68
+
69
+ # 6. Push both branches (maintains stack relationship)
70
+ but push
71
+ ```
72
+
73
+ **Result:** Two PRs where user-profile PR depends on authentication PR. GitHub/GitLab shows the dependency.
74
+
75
+ ## Example 3: Using Absorb Instead of New Commits
76
+
77
+ **Scenario:** Made a small typo fix that should be part of the last commit, not a new commit.
78
+
79
+ ```bash
80
+ # 1. Check current commits and unstaged changes
81
+ but status --json
82
+
83
+ # Output shows:
84
+ # Branch: feature-x (bu)
85
+ # Commits:
86
+ # c3: Implement feature logic
87
+ # c2: Add feature tests
88
+ # Unstaged:
89
+ # a1: fix-typo.js (staged to bu)
90
+
91
+ # 2. Preview what absorb would do (recommended first step)
92
+ but absorb a1 --dry-run # Shows where a1 would be absorbed
93
+
94
+ # 3. Absorb the specific file into appropriate commit
95
+ but absorb a1 # Absorb just this file
96
+
97
+ # GitButler analyzes the change and amends it into c3
98
+ # (because the typo is in code from c3)
99
+ ```
100
+
101
+ **Targeted vs blanket absorb:**
102
+
103
+ ```bash
104
+ but absorb a1 # Absorb specific file (recommended)
105
+ but absorb bu # Absorb all changes staged to branch bu
106
+ but absorb # Absorb ALL uncommitted changes (use with caution)
107
+ ```
108
+
109
+ **Why absorb?** Keeps history clean. Small fixes belong in the commits they fix, not as separate "fix typo" commits.
110
+
111
+ ## Example 4: Reorganizing Commit History
112
+
113
+ ### Scenario A: Squashing Commits
114
+
115
+ **Situation:** Made 5 small WIP commits, want to combine into one logical commit.
116
+
117
+ ```bash
118
+ # Before:
119
+ # c5: More tweaks
120
+ # c4: Fix another thing
121
+ # c3: Fix tests
122
+ # c2: Adjust logic
123
+ # c1: Initial implementation
124
+
125
+ # Squash all commits in branch
126
+ but squash bu
127
+
128
+ # Or squash specific range
129
+ but squash c2..c5 # Squashes c2, c3, c4, c5 into one
130
+
131
+ # Or squash specific commits
132
+ but squash c2 c3 c4 # Squashes these three
133
+ ```
134
+
135
+ ### Scenario B: Moving Files Between Commits
136
+
137
+ **Situation:** A file was committed in the wrong commit, need to move it.
138
+
139
+ ```bash
140
+ # 1. See which files are in which commits
141
+ but status --json -f
142
+
143
+ # Output shows:
144
+ # c3: api.js, utils.js
145
+ # c2: config.js
146
+
147
+ # 2. Move utils.js from c3 to c2
148
+ but rub a2 c2 # File a2 (utils.js) → commit c2
149
+ ```
150
+
151
+ ### Scenario C: Moving Commit to Different Branch
152
+
153
+ **Situation:** Committed to wrong branch, need to move commit.
154
+
155
+ ```bash
156
+ # 1. Check current state
157
+ but status --json
158
+
159
+ # Output:
160
+ # Branch: feature-a (bu)
161
+ # c3: This should be in feature-b!
162
+ # c2: Correct commit
163
+
164
+ # 2. Create or identify target branch
165
+ but branch new feature-b # Creates branch bv
166
+
167
+ # 3. Move the commit
168
+ but move c3 bv # Move c3 to top of branch bv
169
+ ```
170
+
171
+ ## Example 5: Using Marks for Focused Work
172
+
173
+ **Scenario:** Working on a large refactor, want all changes to automatically stage to that branch.
174
+
175
+ ```bash
176
+ # 1. Create refactor branch
177
+ but branch new refactor
178
+
179
+ # 2. Mark it for auto-staging
180
+ but mark bu # Branch bu (refactor) is now marked
181
+
182
+ # 3. Make changes across many files
183
+ # (edit 20 different files)
184
+
185
+ # 4. All changes automatically staged to refactor branch
186
+ but status --json # Shows all changes staged to bu
187
+
188
+ # 5. Commit the staged changes
189
+ but commit bu --only -m "Refactor error handling across app"
190
+
191
+ # 6. Remove mark
192
+ but unmark
193
+ ```
194
+
195
+ **Alternative: Mark a commit for auto-amend**
196
+
197
+ ```bash
198
+ # 1. Create empty commit as placeholder
199
+ but commit empty -m "TODO: Add error handling"
200
+
201
+ # 2. Mark it
202
+ but mark c5 # Commit c5 is now marked
203
+
204
+ # 3. Make changes - they auto-amend into c5
205
+ # (edit files)
206
+
207
+ # 4. Check result
208
+ but show c5 # Shows accumulated changes
209
+
210
+ # 5. Remove mark when done
211
+ but unmark
212
+ ```
213
+
214
+ ## Example 6: Conflict Resolution
215
+
216
+ **Scenario:** After `but pull`, conflicts appear in a commit.
217
+
218
+ ```bash
219
+ # 1. Pull updates
220
+ but pull
221
+
222
+ # Output:
223
+ # Conflict in commit c3 on branch feature-x
224
+
225
+ # 2. Check status
226
+ but status --json
227
+
228
+ # Output:
229
+ # Branch: feature-x (bu)
230
+ # c3: Add validation (CONFLICTED)
231
+
232
+ # 3. Enter resolution mode
233
+ but resolve c3
234
+
235
+ # Output:
236
+ # Entering resolution mode for commit c3
237
+ # Fix conflicts in: api/users.js, api/validation.js
238
+
239
+ # 4. Edit files to resolve conflicts
240
+ # (open files, remove <<< === >>> markers)
241
+
242
+ # 5. Check progress
243
+ but resolve status
244
+
245
+ # Output:
246
+ # Remaining conflicts:
247
+ # api/validation.js
248
+
249
+ # 6. Continue fixing...
250
+ # (resolve last conflict)
251
+
252
+ # 7. Finalize
253
+ but resolve finish
254
+
255
+ # Back to normal workspace mode
256
+ ```
257
+
258
+ ## Example 7: Complete Feature Development Workflow
259
+
260
+ **Scenario:** Building a complete feature from start to finish.
261
+
262
+ ```bash
263
+ # 1. Update to latest
264
+ but pull
265
+
266
+ # 2. Create branch for feature
267
+ but branch new user-dashboard
268
+
269
+ # 3. Make initial changes
270
+ # (create dashboard.js, add routes)
271
+
272
+ # 4. Check and stage
273
+ but status --json
274
+ but stage <file-ids> bu # Stage changes to dashboard branch
275
+
276
+ # 5. First commit
277
+ but commit bu --only -m "Add dashboard route and basic layout"
278
+
279
+ # 6. Continue iterating
280
+ # (add widgets, styling)
281
+ but stage <file-ids> bu
282
+ but commit bu --only -m "Add dashboard widgets"
283
+ but stage <file-ids> bu
284
+ but commit bu --only -m "Style dashboard components"
285
+
286
+ # 7. Make small fix
287
+ # (fix typo in widget)
288
+ but status --json # Check file ID of the fix (e.g., a1)
289
+ but absorb a1 # Absorb specific file into appropriate commit
290
+
291
+ # 8. Review history
292
+ but status --json
293
+
294
+ # 9. Clean up if needed
295
+ but squash bu # Combine all commits (optional)
296
+
297
+ # 10. Push to remote (can also skip - pr new auto-pushes)
298
+ but push bu
299
+
300
+ # 11. Create pull request
301
+ but pr new bu
302
+
303
+ # Output:
304
+ # Created PR #123: https://github.com/org/repo/pull/123
305
+
306
+ # 12. After PR is merged, update
307
+ but pull
308
+ ```
309
+
310
+ ## Example 8: Working with Applied/Unapplied Branches
311
+
312
+ **Scenario:** Have 3 branches, but two are causing conflicts. Temporarily unapply them.
313
+
314
+ ```bash
315
+ # 1. Check active branches
316
+ but status --json
317
+
318
+ # Output:
319
+ # Applied branches:
320
+ # bu: feature-a
321
+ # bv: feature-b
322
+ # bw: feature-c
323
+
324
+ # 2. Conflicts between feature-b and feature-c
325
+ # Unapply them temporarily
326
+ but unapply bv
327
+ but unapply bw
328
+
329
+ # 3. Focus on feature-a
330
+ # (make changes, stage, commit)
331
+ but stage <file-ids> bu
332
+ but commit bu --only -m "Complete feature-a"
333
+
334
+ # 4. Create PR for feature-a (auto-pushes)
335
+ but pr new bu
336
+
337
+ # 5. Reapply other branches
338
+ but apply bv
339
+ but apply bw
340
+
341
+ # 6. Deal with their conflicts now
342
+ but resolve ...
343
+ ```
344
+
345
+ ## Example 9: Fixing History Before Pushing
346
+
347
+ **Scenario:** Made several commits, realized you need to reword messages and reorder.
348
+
349
+ ```bash
350
+ # 1. Current state
351
+ but status --json
352
+
353
+ # Output:
354
+ # Branch: feature-x (bu)
355
+ # c5: final commit
356
+ # c4: WIP
357
+ # c3: Fix stuff
358
+ # c2: Another fix
359
+ # c1: Initial
360
+
361
+ # 2. Reword commit messages
362
+ but reword c4 -m "Add validation logic"
363
+ but reword c3 -m "Fix edge case in parser"
364
+ but reword c2 -m "Update error messages"
365
+
366
+ # 3. Move c5 to be earlier
367
+ but move c5 c3 # Move c5 before c3
368
+
369
+ # 4. Squash similar commits
370
+ but squash c2 c3 # Combine error handling commits
371
+
372
+ # 5. Review final state
373
+ but status --json
374
+
375
+ # Output:
376
+ # Branch: feature-x (bu)
377
+ # c4: Add validation logic
378
+ # c3: final commit
379
+ # c2: Fix edge case in parser and update error messages
380
+ # c1: Initial
381
+
382
+ # 6. Push clean history
383
+ but push bu
384
+ ```
385
+
386
+ ## Example 10: Daily Development Workflow
387
+
388
+ **Typical day working with GitButler:**
389
+
390
+ ```bash
391
+ # Morning: Start day
392
+ but pull # Get latest from team
393
+
394
+ # Start new task
395
+ but branch new fix-auth-bug # Create branch for today's work
396
+
397
+ # Work and commit iteratively
398
+ # (make changes)
399
+ but status --json # Check changes
400
+ but stage <file-ids> bu # Stage to branch
401
+ but commit bu --only -m "Identify auth bug source"
402
+ # (make more changes)
403
+ but stage <file-ids> bu # Stage to branch
404
+ but commit bu --only -m "Fix token expiration handling"
405
+ # (small fix to existing code)
406
+ but status --json # Get file ID (e.g., a1)
407
+ but absorb a1 # Absorb specific fix into appropriate commit
408
+
409
+ # Mid-day: Start urgent fix on different branch
410
+ but branch new hotfix-login # Parallel branch for urgent work
411
+ # (make fix)
412
+ but stage <file-ids> bv # Stage to hotfix branch
413
+ but commit bv --only -m "Fix login redirect loop"
414
+ but pr new bv # Push and create PR immediately
415
+
416
+ # Back to original work
417
+ # (continue working on bu, auth bug fix)
418
+ but stage <file-ids> bu # Stage to auth branch
419
+ but commit bu --only -m "Add tests for token handling"
420
+
421
+ # End of day: Clean up and create PR
422
+ but squash bu # Combine into clean history
423
+ but pr new bu # Push and create PR
424
+
425
+ # After PR review: Make requested changes
426
+ # (make changes based on feedback)
427
+ but status --json # Check file IDs of changes
428
+ but absorb <file-id> # Absorb specific changes into commits
429
+ # Or absorb all changes for this branch:
430
+ but absorb bu # Absorb all changes staged to bu
431
+ but push bu --with-force # Force push updated history
432
+ ```
433
+
434
+ ## Example 11: Recovering from Mistakes
435
+
436
+ **Scenario:** Made changes you didn't mean to, need to undo.
437
+
438
+ ### Undo Last Operation
439
+
440
+ ```bash
441
+ # Made a mistake
442
+ but squash bu # Oops! Didn't mean to squash
443
+
444
+ # Undo it
445
+ but undo # Reverts the squash
446
+ ```
447
+
448
+ ### Restore to Earlier Point
449
+
450
+ ```bash
451
+ # View operation history
452
+ but oplog
453
+
454
+ # Output:
455
+ # s5: squash branch bu
456
+ # s4: commit bu "message"
457
+ # s3: stage files to bu
458
+ # s2: create branch bu
459
+ # s1: pull from remote
460
+
461
+ # Restore to before squash
462
+ but oplog restore s4
463
+ ```
464
+
465
+ ### Discard Uncommitted Changes
466
+
467
+ ```bash
468
+ # Changed a file but want to discard
469
+ but status --json
470
+
471
+ # Output:
472
+ # Unstaged:
473
+ # a1: bad-changes.js
474
+
475
+ # Discard it
476
+ but discard a1
477
+ ```
478
+
479
+ ## Tips and Tricks
480
+
481
+ ### Quick Status Check
482
+
483
+ ```bash
484
+ but status -f # File-centric view for quick overview
485
+ ```
486
+
487
+ ### Preview Before Doing
488
+
489
+ ```bash
490
+ but absorb <file-id> --dry-run # See where specific file would be absorbed
491
+ but push --dry-run # See what would be pushed
492
+ ```
493
+
494
+ ### JSON for Scripting
495
+
496
+ ```bash
497
+ but status --json | jq '.branches[] | .name' # List branch names
498
+ ```
499
+
500
+ ### Auto-completion
501
+
502
+ ```bash
503
+ eval "$(but completions zsh)" # Add to ~/.zshrc
504
+ eval "$(but completions bash)" # Add to ~/.bashrc
505
+ ```
506
+
507
+ ### Viewing History
508
+
509
+ ```bash
510
+ but show bu # Show all commits in branch
511
+ git log bu # Traditional git log (read-only, still works)
512
+ ```