Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rebasing with Git

Honestly, if I had a magic wand, I would also improve git rebase. It’s a killer feature, but feels broken. It’s bold claim, so let me unpack that.

Conflicts

Git instills serenety: it is safely append-only and it treats your filesystem as sacred. You can manipulate history relaxed, knowing Git is never destructive.

Until a rebase conflict. Git then enters danger mode. It basically stops working, offering two exits only: abort, or solve conflicts now, in the exact order demanded.

You cannot do anything else. You can’t cherry-pick or bisect to help fix the code. Got an urgent hotfix? You can’t pause the rebase and checkout another commit. Your project is broken and Git abandoned you exactly when you need it most. No wonder many stick to merges.

Can we de-escalate this?

I’d want a tool that:

  • Reveals all rebase conflicts at once.
  • Stays functional during conflicts.
  • Lets me postpone resolution.
  • Allows solving conflicts using all available features.

Jujutsu is that tool. Conflicts are first-class citizens. No stress, no drama: Jujutsu stays fully functional. You can solve conflicts by editing files, editing different commits, or even performing another rebase.

In practice

Next time you rebase, copy your repo, run jj git init, and try:

jj rebase --source <FROM> --onto <TO>

where:

  • <FROM> indicates where to cut.
  • <TO> indicates where to paste.

To move 3-4-5-6 on top of 11:

jj log
○  11          <---- paste
○  10
○  9
│ ○  8
│ ○  7
├─╯
│ ○  6
│ ○  5
│ ○  4
│ ○  3         <---- cut
├─╯
~
jj rebase -s 3 -o 11
○  6
○  5
○  4
○  3
○  11          <---- paste
○  10
○  9
│ ○  8
│ ○  7
├─╯
~

If there are conflicts, jj log shows them:

○  11
│ ×  6           <---- conflict
│ ×  5           <---- conflict
│ ○  4
├─╯
~

You can fix conflicts exactly where they are:

jj edit 5

Fixing 5 often propagates the resolution to 6.

Whenever you need, jj undo will be your best friend.