Your First Stack¶
This tutorial walks you through creating your first stack of pull requests.
Scenario¶
You're building a user authentication feature. Instead of one massive PR, you'll create three focused PRs:
- Database models - User table and migrations
- API endpoints - Login/logout routes
- UI components - Login form
Step 1: Start from Main¶
Make sure you're on your trunk branch with a clean working tree:
Step 2: Create the First Branch¶
Create a branch for the database models:
Now make your changes:
# Create your model files
echo "CREATE TABLE users..." > migrations/001_users.sql
# Commit the changes
git add .
git commit -m "Add user database models"
Step 3: Stack the Second Branch¶
Without switching back to main, create the next branch on top:
This branch now includes all changes from feature/auth-models.
Add the API code:
# Create API files
echo "pub fn login()..." > src/api/auth.rs
git add .
git commit -m "Add authentication API endpoints"
Step 4: Stack the Third Branch¶
Create the UI branch:
Add the UI components:
echo "<form>...</form>" > src/components/login.html
git add .
git commit -m "Add login UI components"
Step 5: View Your Stack¶
See the full stack structure:
Output:
Step 6: Navigate the Stack¶
Move between branches easily:
# Go down to parent
gt down
# Now on feature/auth-api
# Go to the bottom
gt bottom
# Now on feature/auth-models
# Go to the top
gt top
# Now on feature/auth-ui
Step 7: Submit All PRs¶
Submit the entire stack as pull requests:
Stack creates three PRs:
| PR | Title | Base |
|---|---|---|
| #1 | Add user database models | main |
| #2 | Add authentication API endpoints | feature/auth-models |
| #3 | Add login UI components | feature/auth-api |
PR Descriptions
Stack automatically adds a stack visualization to each PR description showing where it fits in the stack.
Step 8: Handle Reviews¶
If reviewers request changes to the models PR:
# Go to that branch
gt checkout feature/auth-models
# Make changes
git add .
gt modify # Amends the commit
# Restack dependent branches
gt restack
# Push updates
gt submit
Step 9: Land the Stack¶
Once PRs are approved:
# Merge the first PR
gt land feature/auth-models
# Sync to update the stack
gt sync
# Now feature/auth-api targets main directly
# Merge it
gt land feature/auth-api
# And so on...
Tips for Effective Stacks¶
- Keep branches focused - Each branch should do one thing well
- Commit early, commit often - Use
gt modifyto amend as needed - Restack regularly - Run
gt restackafter changes to parent branches - Use descriptive names - Branch names become part of PR titles
What's Next?¶
- Commands Reference - Learn all available commands
- Workflow Patterns - Common patterns and best practices
- Resolving Conflicts - Handle merge conflicts