Using Jujutsu (jj)
Overview
Jujutsu (jj) is a Git-compatible VCS that treats commits as mutable objects identified by a Change ID. It emphasizes a "stacked diffs" workflow where you can easily manipulate history.
When to Use
- •Always when a
.jjdirectory exists in the project root. - •Creating commits, branches (bookmarks), and PRs.
- •Rebasing, splitting, or squashing changes.
Core Concepts
- •Change ID: Constant identifier (e.g.,
kkmpptxz) for a change. Persists across rewrites. - •Commit ID: Git SHA (e.g.,
a1b2c3d). Changes every time you modify the revision. - •Bookmark: Equivalent to a Git branch. Points to a specific revision.
- •Working Copy (@): The revision you are currently editing.
Workflow: Creating a PR
- •Work: Make changes in the working copy.
- •Describe:
jj describe -m "feat: description" - •Bookmark:
jj bookmark create <branch-name> - •Push:
jj git push --bookmark <branch-name> - •PR:
gh pr create
Common Operations
| Goal | Git Command | JJ Command |
|---|---|---|
| Status | git status | jj st |
| Log | git log --graph | jj log |
| Commit | git add . && git commit | jj describe -m "msg" (no staging needed) |
| Amend | git commit --amend | jj describe -m "new msg" (metadata) or edit files (content) |
| New Branch | git switch -c feat | jj new -m "feat" && jj bookmark create feat |
| Switch | git switch main | jj edit main (edits existing) or jj new main (new on top) |
| Push | git push | jj git push |
| Pull | git pull | jj git fetch (updates remote pointers, doesn't merge) |
Stacking & Reshaping
- •Rebase:
jj rebase -s <revision> -d <destination> - •Split:
jj split(interactive split of current change) - •Squash:
jj squash(moves changes into parent)
Red Flags / Anti-Patterns
- •❌ Don't use
gitcommands directly for creating commits/branches (exceptghCLI). - •❌ Don't panic about "detached HEAD". JJ is always detached. Use
jj newto start fresh. - •❌ Don't forget to push bookmarks. Changes without bookmarks are local-only.
Troubleshooting
- •Conflict:
jjrecords conflicts in the file. Edit file to resolve<<<<markers, then nogit addneeded. - •Lost:
jj op logshows operation history.jj undoworks like magic.