The Developer’s Cry

a blog about computer programming

Jujutsu who?

Programmers use git. In today’s world that’s such a given, that it’s almost a strange thing to say, akin to stating “the sky is blue”. Of course programmers use git! Git is nearly synonymous with source code version control. And then we find the odd Linux kernel developer who uses subversion because that’s what works for him. Or the professional game developer who stubbornly sticks to TortoiseSVN because that’s all he knows and wants to be bothered with. I even know the story of a small company that developed their own source code management system because they were unhappy with how git handles conflicts.

Git is the defacto tool for doing source code version control. It is by no means easy to use, however. Git is very technical, and I bet you’re not even familiar with half of the many things it can do. What bothers me most about git is that it doesn’t actually synchronize client and server for you—that task is left to the developer themselves; synchronizing is a very manual process. The user experience is arcane and not nearly as smooth as you would like sync-and-share to be. I don’t have a perfect solution for this, but now I should mention jujutsu.

Jujutsu is an alternative to git that builds on and works with the git repository. Jujutsu has its own particular workflow that seems easier than git. Like git, jujutsu has many commands. You have to learn these commands, you have to know certain details about these commands, and you have to learn when to use what. The jujutsu workflow feels comfortable, but then it also did some things that made me cry out loud, “what is happening, people?” Jujutsu likes doing stuff under the hood, and then it has its own commit ids while my mind is still half operating in git mode. Oof.

I still recommend you try out jujutsu, maybe you’ll love it. That said, it inspired me to craft a simple shell script to automate and streamline my most-used git workflow. So now instead of jj, I type xx.

    xx new [branch]         create a new branch

The new command creates a new branch and pushes it to the remote. The default branch name is just “xx” in case I’m lazy and can’t be bothered with making up a decent branch name right now. If there are currently uncommitted changes, it will error out.

    xx commit [-m msg]      commit and push

The commit command makes a git commit and pushes it to the remote. This ensures any commits are also stored on the server. It’s nice knowing there’s a backup copy elsewhere, always. Pushing can only be done if there are no conflicts. Therefore work on a personal fork, personal branch, where basically no conflicts can happen.

    xx merge [-m msg]       squash merge branch

The merge command performs a squash merge into the main branch and pushes it to the remote.

    xx cancel               drop changes + delete branch

The cancel command uses git stash drop to drop all current changes and it deletes the branch, both locally and remote. It will never delete the main or master branch.

There are more commands to the xx script, but you get the idea. By the way, it’s also possible to define aliases and add your own subcommands in gitconfig.

The xx script takes advantage of two useful git commands:

branch=$(git branch --show-current)

git diff-index --quiet HEAD
if [ $? -ne 0 ]
then
    echo "There are uncommitted changes"
    exit 255
fi

It’s not fancy, but it doesn’t need to be. The main point is, you don’t have to type a series of git commands all the time. Nor do you need to learn jujutsu martial art. The xx script is no silver bullet and maybe jujutsu is a lot better, pick what works for you.

What’s so great about the UNIX toolbox is that you can easily bend it to your will. Every smart devguy (or gal) has their own little hacks that are just quality of life improvements.