| name | using-git-machete |
| description | git-machete command-line expertise covering branch tree management, fork-point
mechanics, rebase-driven syncing, and stacked-PR workflows on GitHub.
Use when building or maintaining a tree of dependent branches, rebasing chains
of feature branches against `main`, debugging fork-point inference after
force-pushes or squashes, or driving stacked GitHub PRs with `git machete
github` subcommands. Also use for `.git/machete` edits, `traverse` flag
selection, and `advance`/`slide-out` after merges.
|
Using git-machete
Expert guidance for managing branch trees and stacked PRs with git-machete (v3.x).
Quick Start
For immediate help, identify your task type and consult the relevant reference:
| Working On | Reference File | Key Topics |
|---|
| discover, edit, add, status, traverse, slide-out | core-commands | Branch tree CRUD, traversal flags, status -L |
| fork-point overrides, advance, squash, reapply | fork-points-and-rebase | Fork-point inference, overrides, annotations |
| github checkout-prs, create-pr, restack-pr, retarget-pr, anno-prs, update-pr-descriptions | github-integration | Stacked PRs, retarget, anno-prs |
Core Principles
.git/machete Is the Source of Truth
The branch tree lives in .git/machete, an indented text file. Most "machete is wrong" problems are solved by running git machete edit and fixing the indentation by hand.
git machete edit
cat .git/machete
status -L Is the Default Diagnostic
Always start with git machete status -L (or --list-commits). It shows the tree, sync state of each branch versus its parent, and the commits unique to each branch. Plain status hides the commits and hides why a branch is out of sync.
git machete status -L
git machete status -L --color=always | less -R
Let traverse Drive Rebases — Don't Run git rebase Yourself
git machete traverse walks the tree, rebases each branch onto its parent's tip using machete's fork-point inference, and (optionally) pushes. Running git rebase directly on a managed branch bypasses fork-point logic and creates duplicate commits on the next traverse.
git machete traverse --fetch --start-from=root --return-to=here
Trust Fork-Point Inference Until It's Wrong, Then Override Explicitly
Fork-points are inferred from the reflog. Force-pushes, upstream squash-merges, and rebases off the chain corrupt that inference. Fix with --override-to-inferred or --override-to=<commit> rather than editing history blindly.
git machete fork-point --override-to-inferred my-branch
git machete fork-point --override-to=abc1234 my-branch
git machete fork-point --unset-override my-branch
After a PR Merges, advance — Don't slide-out
When a child branch's commits land on its parent (typical after a squash-merge or fast-forward merge), git machete advance fast-forwards the parent and slides the child out of the tree in one step. Use slide-out only when the branch was abandoned without merging.
git machete go down && git machete advance
Common Pattern Template
The canonical daily loop for a managed tree:
git machete status -L
git machete traverse --fetch --push --start-from=first-root
git machete status -L
For starting a new feature on top of an existing branch:
git checkout parent-branch
git machete add new-feature --onto=parent-branch --as-first-child
git machete traverse --push
Anti-Patterns
Editing .git/machete to Remove a Merged Branch
$EDITOR .git/machete
git checkout merged-child
git machete advance
Running git rebase on a Managed Branch
git checkout feature-b
git rebase feature-a
git machete update
git machete traverse
Force-Pushing Without --force-with-lease After a Rebase
git push --force
git push --force-with-lease
git machete traverse --push
Trusting Fork-Point After a Squash-Merge Upstream
git machete traverse
git machete fork-point --override-to=<squash-sha> child-branch
git machete traverse
Reference File IDs
For programmatic access: core-commands · fork-points-and-rebase · github-integration