Moving Bookmarks
Important
You find out that there is no current branch following your work as you commit.
Did you notice the mysterious jj bookmark advance command? It
deserves a few words.
The main observation worth noting is how and when Git and Jujutsu decide to move local branches.
In Jujutsu, Bookmarks stick to the Change they were created on. If you
move history trees around, the Bookmarks move with them. They stick to
Changes, not to the underlying Git commits. Git can do this via
rebase --update-refs1; in Jujutsu, it’s the default.
Bookmarks Don’t Follow Commits
Git has a notion of current branch which automatically advances as you create commits.
Jujutsu has not: a Bookmark never replaces the Change it points to,
unless explicitly told to. Look what happens with jj commit (which
is just jj desc followed by jj new):
jj git init
jj bookmark create main
jj commit -m "Hello"
@ w (empty)
○ k (empty) Hello **main**
◆ z (empty)
echo 'print("Hello, World!")' > main.py
jj squash
jj commit -m "Hola"
echo 'print("Hola, Mundo!")' >> main.py
jj squash
@ n (empty)
○ o Hola
○ k Hello **main**
◆ z (empty)
main stayed behind, stuck to k.
Git does the opposite, and it is easy to see why: after git commit,
if the branch was not moved onto your new commit, you would be left in
detached head, a condition that Git considers dangerous. Jujutsu has
a different opinion on danger.
Manually Updating Bookmark Positions
Isn’t updating Bookmarks by hand annoying? Indeed, this makes newcomers frown. I promise you’ll appreciate its elegance over time.
Jujutsu constantly nudges you toward code reviews. If you think about
it, the Squash Workflow revolves around the idea of giving you a
chance to run jj diff before finalizing your edits. Similarly,
tree manipulation is so pervasive that it makes sense to explicitly
review history before moving Bookmarks and pushing them.
Even further: typically, Bookmarks are created at the very last moment, right before opening a Pull Request. Idiomatically, Jujutsu is used as a branchless system.
Bottom line: jj bookmark advance let you manually do what git commit does automatically, giving you a review phase before pushing.
That’s all for local Bookmarks. Things get more interesting when remotes come into play.
-
https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt—update-refs ↩