Reviewing teammate work locally
One trick I like is using jj restore to review someone else’s branch as dirty local changes.
I start from a clean change on top of main:
jj git fetch
jj new main
Then I restore a teammate’s remote branch into my working copy:
jj restore -f feature/example-change@origin
What this does
This restores the file contents from that remote branch into my current working-copy change. It is a tree restore, not "apply only the PR patch". If the branch is based on a different point, the dirty diff may include more than I expected.
Now the restored branch contents are a diff in my workspace:
jj status
jj diff
jj diff --git
That is neat because I can review it like normal code, but I can also reshape it locally.
For example, I can commit a local version:
jj commit -m "review: inspect teammate branch locally"
jj diff -r @-
Or split the change while I am trying to understand it:
jj split
If I never committed the local review, I can throw away the restored files by going back to main:
jj restore -f main
If I did commit a local review change, jj commit left me on a new empty @, so the review commit is @-:
jj abandon @-
Why I use this
GitHub shows me a diff. This gives me a working tree. I can run tests, move code around, make experimental commits, and then throw it all away.
I anonymized the branch name here on purpose. In real work it is usually some feature branch from a teammate or a generated PR branch.
There are other shapes for the same idea.
I can duplicate the teammate’s commit and experiment on my copy:
jj duplicate <change>
Or I can create a new change on top of their work:
jj new feature/example-change@origin
That is the safer beginner move when I want to run the branch as-is before making local experiments. The restore trick is for when I specifically want their branch contents as dirty changes on my own base.
This is why I like doing reviews with jj: the branch is no longer a read-only diff in a browser. It is local code I can test, split, duplicate, abandon, and undo without disturbing the author’s branch.