Janik von Rotz


4 min read

Git and Jujutsu

To know how to git is to know pain. I wouldn’t describe myself as a master of git. Never done the bisect and rebase onto stuff. Because git is my daily driver on the command line I am always interested to learn how to use it better.

One thing that seems to be a good fit for git is jujutsu. It showed up in my feed once again.

In software engineering git has become single most important tool. But as mentioned some parts of git are and will always be a hassle. One such thing is rewriting the history and it seems jujutsu solves exactly that.

Lets head over to https://docs.jj-vcs.dev/latest/install-and-setup/ and install jujutsu. In my case installing a new tool means extending the https://codeberg.org/janikvonrotz/dotfiles repo.

The jujutsu cli can be invoked with jj. Lets do our first commit in the Odoo-Build repo.

When I checked the status of the repo I got this:

*[main][~/Odoo-Build]$ jj status
Error: There is no jj repo in "."
Hint: It looks like this is a git repo. You can create a jj repo backed by it by running this:
jj git init

Ok, so jj does not work directly with a git repo.

*[main][~/Odoo-Build]$ jj git init
Done importing changes from the underlying Git repo.
Setting the revset alias `trunk()` to `main@origin`
Hint: The following remote bookmarks aren't associated with the existing local bookmarks:
  chore-task-script-style-guide@origin
  main@origin
Hint: Run the following command to keep local bookmarks updated on future pulls:
  jj bookmark track chore-task-script-style-guide --remote=origin
  jj bookmark track main --remote=origin
Initialized repo in "."
Hint: Running `git clean -xdf` will remove `.jj/`!

Not sure what bookmarks are, but they seem important. Let’s check status again.

*[main][~/Odoo-Build]$ jj status
Working copy changes:
M bin/upgrade-odoo
Working copy  (@) : yxssyntv 7e4c4ccf (no description set)
Parent commit (@-): kwlvwrwt 8d967000 main main@origin | fix(upgrade-odoo): correct typo in drop-database condition

And now the commit!

*[main][~/Odoo-Build]$ jj commit
Working copy  (@) now at: xtkvuony 270d625b (empty) (no description set)
Parent commit (@-)      : yxssyntv 3a37f97a feat(odoo-upgrade): improve script
Warning: Name and email not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes.
Hint: To configure, run:
  jj config set --user user.name "Some One"
  jj config set --user user.email "someone@example.com"

Mhm, so jujutsu is not aware of the git config. Switching into the dotfiles project.

Defined a config.toml and symlinked it.

Then I looked up the flow to commit to main:

jj log
jj commit -m "msg"
jj bookmark set --revision @- main
jj git push -r @-
jj op log

I assume this is done once. Lets try it.

*[main][~/dotfiles]$ jj st
Working copy changes:
A jujutsu/config.toml
Working copy  (@) : qwsmynwm 5dbd8abe (no description set)
Parent commit (@-): psztsywm 2f76627e main main@origin | feat(prompts): create symlink to jujutsu config after installation

*[main][~/dotfiles]$ jj commit -m "feat(jujutsu): add config"
Working copy  (@) now at: xmpwvrys 48e0daa3 (empty) (no description set)
Parent commit (@-)      : qwsmynwm 698ba34e feat(jujutsu): add config

[698ba34][~/dotfiles]$ jj bookmark set --revision @- main
Moved 1 bookmarks to qwsmynwm 698ba34e main* | feat(jujutsu): add config

[698ba34][~/dotfiles]$ jj git push -r @-
Warning: Non-tracking remote bookmark main@origin exists
Hint: Run `jj bookmark track main --remote=origin` to import the remote bookmark.
Nothing changed.

Something has been committed. But remote tracking did not work.

Trying to push through…

[698ba34][~/dotfiles]$ jj git push
Warning: Non-tracking remote bookmark main@origin exists
Hint: Run `jj bookmark track main --remote=origin` to import the remote bookmark.
Nothing changed.

[698ba34][~/dotfiles]$ jj bookmark track main --remote=origin
Started tracking 1 remote bookmarks.

[698ba34][~/dotfiles]$ jj git push
Changes to push to origin:
  Move forward bookmark main from 2f76627e4984 to 698ba34edd9c
git: Enumerating objects: 5, done.
git: Counting objects: 100% (5/5), done.
git: Delta compression using up to 16 threads
git: Compressing objects: 100% (3/3), done.
git: Writing objects: 100% (4/4), 438 bytes | 438.00 KiB/s, done.
git: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
[698ba34][~/dotfiles]$

It worked! Obviously, I lack the understanding of what went on. I have to understand what bookmarks are and how the interaction with git remotes works.

There is a guide on how to interact with GitHub: https://docs.jj-vcs.dev/latest/github/

And here is an explainer on bookmarks: https://docs.jj-vcs.dev/latest/bookmarks/

Also I think it is worth trying jujutsu without git. In that regards gerrit seem very interesting: https://gerrithub.io/Documentation/intro-how-gerrit-works.html

Category: Software tooling
Tags: 100daystooffload , git , jujutsu , vcs
Edit this page
Show statistic for this page