Try jj vcs without risk in your git repo

I have been happily using jj vcs instead of git for 6 months now and I will never go back.

The reason I started was because jj was supposed to be better at handling stacked PRs. Spoiler alert: it is.

With jj I don't have to create branches until I am ready, nor do I have to create commits or commit messages until I am ready. I just work with sets of changes and I move them around as I please. When I have to modify something at the bottom of the stack, maybe from a review comment, the change propagates automatically up the stack. Any conflicts are just saved in the files for me to deal with when I am ready. The good news is that you can try jj in your existing git repo without damaging anything and you can use git commands whenever you feel you need to and just go back to git if that is how you feel, no harm done.

The best thing is that my team-mates are all still using git and it just works.

OK, let's give it a go! 

  1. Follow the install instructions from the jj docs
  2. Go into your cloned git repo and run the command jj git init --colocate
  3. You will probably get prompted to run jj bookmark track main@origin. You can also do the same for any other remote branches you want to track.
  4. Then do jj new main to create an empty change on top of main and start writing code!

To view what files have been changed, run jj st. To see where in the tree you are working, run jj log

 Feel free to also see how things look from git's perspective. Note that jj mostly works in a detached head state. This might feel a bit strange, but all your git commands work as they should and you can stop using jj whenever you want.

Interacting with remote

Get updates from remote with jj git fetch. If you need to, jj rebase -d main.

When you are ready, create a description (a commit message) with jj describe -m "feat: my changes"

To commit to main, jj bookmark move main --to @. To create a new branch for a PR, jj bookmark create my-bookmark

Then just jj git push. You need to add --allow-new if you created a new bookmark.

Is that it?

Pretty much.  Obviously there are more commands for use when needed, but jj is both much simpler than git, by only working with changes and bookmarks, and much more powerful than git by allowing you to move and partition your changes as you like without the painful details of how git works.

When you do jj log, you will see an @ for your current working change, a change ID consisting of letters with the unique prefix highlighted, a commit hash and possibly a bookmark (branch name). A change can be referred to by the change ID prefix (or longer), the commit hash, or the bookmark. There is a whole revset language for specifying sets of changes and changes relative to specific changes.

You don't have to work at the top of a branch, you can edit any change in the branch, or insert a new change anywhere in the tree.

 Give it a whirl, it takes less than a week to get used to. I think you will like it, but if you don't, just go back to using git commands.

 

Comments

Popular Posts