2022-12-03 14:22:02 +00:00
|
|
|
# Using Jujutsu with GitHub and GitLab Projects
|
|
|
|
|
2023-01-19 16:28:00 +00:00
|
|
|
This guide assumes a basic understanding of either Git or Mercurial.
|
2022-12-03 14:22:02 +00:00
|
|
|
|
|
|
|
## Set up an SSH key
|
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
As of October 2023 it's recommended to set up an SSH key to work with GitHub
|
2023-01-19 16:28:00 +00:00
|
|
|
projects. See [GitHub's Tutorial][gh]. This restriction may be lifted in the
|
|
|
|
future, see [issue #469][http-auth] for more information and progress on
|
2023-10-24 21:09:13 +00:00
|
|
|
authenticated HTTP.
|
2022-12-03 14:22:02 +00:00
|
|
|
|
|
|
|
## Basic workflow
|
2023-01-19 16:28:00 +00:00
|
|
|
|
2023-08-24 22:33:49 +00:00
|
|
|
The simplest way to start with Jujutsu is to create a stack of commits first.
|
2024-08-21 19:59:15 +00:00
|
|
|
You will only need to create a bookmark when you need to push the stack to a
|
|
|
|
remote. There are two primary workflows: using a generated bookmark name or
|
|
|
|
naming a bookmark.
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
### Using a generated bookmark name
|
2023-08-24 22:33:49 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
In this example we're letting Jujutsu auto-create a bookmark.
|
2023-10-24 21:09:13 +00:00
|
|
|
|
2023-08-13 01:38:57 +00:00
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
# Start a new commit off of the default bookmark.
|
2022-12-03 14:22:02 +00:00
|
|
|
$ jj new main
|
|
|
|
# Refactor some files, then add a description and start a new commit
|
|
|
|
$ jj commit -m 'refactor(foo): restructure foo()'
|
|
|
|
# Add a feature, then add a description and start a new commit
|
|
|
|
$ jj commit -m 'feat(bar): add support for bar'
|
2024-08-21 19:59:15 +00:00
|
|
|
# Let Jujutsu generate a bookmark name and push that to GitHub. Note that we
|
2023-10-24 21:09:13 +00:00
|
|
|
# push the working-copy commit's *parent* because the working-copy commit
|
|
|
|
# itself is empty.
|
2023-09-26 00:06:50 +00:00
|
|
|
$ jj git push -c @-
|
2022-12-03 14:22:02 +00:00
|
|
|
```
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
### Using a named bookmark
|
2023-08-24 22:33:49 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
In this example, we create a bookmark named `bar` and then push it to the remote.
|
2023-08-24 22:33:49 +00:00
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
# Start a new commit off of the default bookmark.
|
2023-08-24 22:33:49 +00:00
|
|
|
$ jj new main
|
|
|
|
# Refactor some files, then add a description and start a new commit
|
|
|
|
$ jj commit -m 'refactor(foo): restructure foo()'
|
|
|
|
# Add a feature, then add a description and start a new commit
|
|
|
|
$ jj commit -m 'feat(bar): add support for bar'
|
2024-08-21 19:59:15 +00:00
|
|
|
# Create a bookmark so we can push it to GitHub. Note that we created the bookmark
|
2023-10-24 21:09:13 +00:00
|
|
|
# on the working-copy commit's *parent* because the working copy itself is empty.
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj bookmark create bar -r @- # `bar` now contains the previous two commits.
|
|
|
|
# Push the bookmark to GitHub (pushes only `bar`)
|
2023-08-24 22:33:49 +00:00
|
|
|
$ jj git push
|
|
|
|
```
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
While it's possible to create a bookmark in advance and commit on top of it in a
|
|
|
|
Git-like manner, you will then need to move the bookmark manually when you create
|
2023-10-24 21:09:13 +00:00
|
|
|
a new commits. Unlike Git, Jujutsu will not do it automatically.
|
|
|
|
|
|
|
|
## Updating the repository
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
As of October 2023, Jujutsu has no equivalent to a `git pull` command (see
|
|
|
|
[issue #1039][sync-issue]). Until such a command is added, you need to use
|
2024-08-21 19:59:15 +00:00
|
|
|
`jj git fetch` followed by a `jj rebase -d $main_bookmark` to update your
|
2023-10-24 21:09:13 +00:00
|
|
|
changes.
|
2023-01-19 16:28:00 +00:00
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
[sync-issue]: https://github.com/martinvonz/jj/issues/1039
|
2022-12-03 14:22:02 +00:00
|
|
|
|
|
|
|
## Working in a Git co-located repository
|
|
|
|
|
2024-02-25 11:39:42 +00:00
|
|
|
After doing `jj git init --colocate`, Git will be in a [detached HEAD
|
2024-08-21 19:59:15 +00:00
|
|
|
state][detached], which is unusual, as Git mainly works with bookmarks. In a
|
2024-02-25 11:39:42 +00:00
|
|
|
co-located repository, every `jj` command will automatically synchronize
|
|
|
|
Jujutsu's view of the repo with Git's view. For example, `jj commit` updates the
|
|
|
|
HEAD of the Git repository, enabling an incremental migration.
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2023-08-13 01:38:57 +00:00
|
|
|
```shell
|
2022-12-03 14:22:02 +00:00
|
|
|
$ nvim docs/tutorial.md
|
|
|
|
$ # Do some more work.
|
|
|
|
$ jj commit -m "Update tutorial"
|
2024-08-21 19:59:15 +00:00
|
|
|
# Create a bookmark on the working-copy commit's parent
|
|
|
|
$ jj bookmark create doc-update -r @-
|
2023-08-14 00:35:11 +00:00
|
|
|
$ jj git push
|
2022-12-03 14:22:02 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Working in a Jujutsu repository
|
2023-01-19 16:28:00 +00:00
|
|
|
|
|
|
|
In a Jujutsu repository, the workflow is simplified. If there's no need for
|
2024-08-21 19:59:15 +00:00
|
|
|
explicitly named bookmarks, you can just generate one for a change. As Jujutsu is
|
|
|
|
able to create a bookmark for a revision.
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2023-08-13 01:38:57 +00:00
|
|
|
```shell
|
2022-12-03 14:22:02 +00:00
|
|
|
$ # Do your work
|
2023-08-14 00:35:11 +00:00
|
|
|
$ jj commit
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Push change "mw", letting Jujutsu automatically create a bookmark called
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # "push-mwmpwkwknuz"
|
|
|
|
$ jj git push --change mw
|
2022-12-03 14:22:02 +00:00
|
|
|
```
|
|
|
|
|
2023-01-19 16:28:00 +00:00
|
|
|
## Addressing review comments
|
|
|
|
|
|
|
|
There are two workflows for addressing review comments, depending on your
|
|
|
|
project's preference. Many projects prefer that you address comments by adding
|
2024-08-21 19:59:15 +00:00
|
|
|
commits to your bookmark[^1]. Some projects (such as Jujutsu and LLVM) instead
|
2023-01-19 16:28:00 +00:00
|
|
|
prefer that you keep your commits clean by rewriting them and then
|
|
|
|
force-pushing[^2].
|
|
|
|
|
|
|
|
### Adding new commits
|
|
|
|
|
|
|
|
If your project prefers that you address review comments by adding commits on
|
|
|
|
top, you can do that by doing something like this:
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2023-08-13 01:38:57 +00:00
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Create a new commit on top of the `your-feature` bookmark from above.
|
2023-04-11 20:03:53 +00:00
|
|
|
$ jj new your-feature
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # Address the comments by updating the code. Then review the changes.
|
2022-12-03 14:22:02 +00:00
|
|
|
$ jj diff
|
|
|
|
$ # Give the fix a description and create a new working-copy on top.
|
|
|
|
$ jj commit -m 'address pr comments'
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Update the bookmark to point to the new commit.
|
|
|
|
$ jj bookmark set your-feature -r @-
|
2022-12-03 14:22:02 +00:00
|
|
|
$ # Push it to your remote
|
2023-08-24 22:33:49 +00:00
|
|
|
$ jj git push
|
|
|
|
```
|
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
Notably, the above workflow creates a new commit for you. The same can be
|
|
|
|
achieved without creating a new commit.
|
2023-08-24 22:33:49 +00:00
|
|
|
|
|
|
|
> **Warning**
|
|
|
|
> We strongly suggest to `jj new` after the example below, as all further edits
|
|
|
|
> still get amended to the previous commit.
|
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Create a new commit on top of the `your-feature` bookmark from above.
|
2023-08-24 22:33:49 +00:00
|
|
|
$ jj new your-feature
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # Address the comments by updating the code. Then review the changes.
|
2023-08-24 22:33:49 +00:00
|
|
|
$ jj diff
|
|
|
|
$ # Give the fix a description.
|
|
|
|
$ jj describe -m 'address pr comments'
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Update the bookmark to point to the current commit.
|
|
|
|
$ jj bookmark set your-feature -r @
|
2023-08-24 22:33:49 +00:00
|
|
|
$ # Push it to your remote
|
|
|
|
$ jj git push
|
2022-12-03 14:22:02 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Rewriting commits
|
2023-01-19 16:28:00 +00:00
|
|
|
|
|
|
|
If your project prefers that you keep commits clean, you can do that by doing
|
|
|
|
something like this:
|
|
|
|
|
2023-08-13 01:38:57 +00:00
|
|
|
```shell
|
2022-12-03 14:22:02 +00:00
|
|
|
$ # Create a new commit on top of the second-to-last commit in `your-feature`,
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # as reviewers requested a fix there.
|
2023-09-26 17:47:42 +00:00
|
|
|
$ jj new your-feature- # NOTE: the trailing hyphen is not a typo!
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # Address the comments by updating the code. Then review the changes.
|
2023-08-14 00:35:11 +00:00
|
|
|
$ jj diff
|
2022-12-03 14:22:02 +00:00
|
|
|
$ # Squash the changes into the parent commit
|
|
|
|
$ jj squash
|
2024-08-21 19:59:15 +00:00
|
|
|
$ # Push the updated bookmark to the remote. Jujutsu automatically makes it a
|
2023-10-24 21:09:13 +00:00
|
|
|
$ # force push
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj git push --bookmark your-feature
|
2022-12-03 14:22:02 +00:00
|
|
|
```
|
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
The hyphen after `your-feature` comes from the
|
|
|
|
[revset](https://github.com/martinvonz/jj/blob/main/docs/revsets.md) syntax.
|
2023-09-26 17:47:42 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
## Working with other people's bookmarks
|
2023-08-24 22:33:49 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
By default, `jj git clone` imports the default remote bookmark (which is usually
|
|
|
|
`main` or `master`), but `jj git fetch` doesn't import new remote bookmarks to
|
|
|
|
local bookmarks. This means that if you want to iterate or test another
|
|
|
|
contributor's bookmark, you'll need to do `jj new <bookmark>@<remote>` onto it.
|
2023-12-16 10:01:44 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
If you want to import all remote bookmarks including inactive ones, set
|
|
|
|
`git.auto-local-bookmark = true` in the config file. Then you can specify a
|
|
|
|
contributor's bookmark as `jj new <bookmark>` instead of `jj new <bookmark>@<remote>`.
|
2023-08-24 22:33:49 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
You can find more information on that setting [here][auto-bookmark].
|
2023-08-24 22:33:49 +00:00
|
|
|
|
2023-03-26 22:02:59 +00:00
|
|
|
## Using GitHub CLI
|
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
GitHub CLI will have trouble finding the proper Git repository path in jj repos
|
2023-03-26 22:02:59 +00:00
|
|
|
that aren't [co-located](./git-compatibility.md#co-located-jujutsugit-repos)
|
|
|
|
(see [issue #1008]). You can configure the `$GIT_DIR` environment variable to
|
|
|
|
point it to the right path:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ GIT_DIR=.jj/repo/store/git gh issue list
|
|
|
|
```
|
|
|
|
|
|
|
|
You can make that automatic by installing [direnv](https://direnv.net) and
|
2023-10-24 21:09:13 +00:00
|
|
|
defining hooks in a `.envrc` file in the repository root to configure `$GIT_DIR`.
|
|
|
|
Just add this line into `.envrc`:
|
2023-03-26 22:02:59 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
export GIT_DIR=$PWD/.jj/repo/store/git
|
|
|
|
```
|
|
|
|
|
|
|
|
and run `direnv allow` to approve it for direnv to run. Then GitHub CLI will
|
|
|
|
work automatically even in repos that aren't co-located so you can execute
|
|
|
|
commands like `gh issue list` normally.
|
|
|
|
|
|
|
|
[issue #1008]: https://github.com/martinvonz/jj/issues/1008
|
|
|
|
|
2022-12-03 14:22:02 +00:00
|
|
|
## Useful Revsets
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
Log all revisions across all local bookmarks that aren't on the main bookmark nor
|
2023-10-24 21:09:13 +00:00
|
|
|
on any remote:
|
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj log -r 'bookmarks() & ~(main | remote_bookmarks())'
|
2023-10-24 21:09:13 +00:00
|
|
|
```
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
Log all revisions that you authored, across all bookmarks that aren't on any
|
2023-10-24 21:09:13 +00:00
|
|
|
remote:
|
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj log -r 'mine() & bookmarks() & ~remote_bookmarks()'
|
2023-10-24 21:09:13 +00:00
|
|
|
```
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
Log all remote bookmarks that you authored or committed to:
|
2023-10-24 21:09:13 +00:00
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj log -r 'remote_bookmarks() & (mine() | committer(your@email.com))'
|
2023-10-24 21:09:13 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Log all descendants of the current working copy that aren't on any remote:
|
|
|
|
|
|
|
|
```shell
|
2024-08-21 19:59:15 +00:00
|
|
|
$ jj log -r '::@ & ~remote_bookmarks()'
|
2023-10-24 21:09:13 +00:00
|
|
|
```
|
2022-12-03 14:22:02 +00:00
|
|
|
|
|
|
|
## Merge conflicts
|
|
|
|
|
2023-01-19 16:28:00 +00:00
|
|
|
For a detailed overview, how Jujutsu handles conflicts, revisit
|
|
|
|
the [tutorial][tut].
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
[^1]:
|
|
|
|
This is a GitHub-style review, as GitHub currently only is able to compare
|
2024-08-21 19:59:15 +00:00
|
|
|
bookmarks.
|
2023-08-13 02:16:41 +00:00
|
|
|
|
2023-10-24 21:09:13 +00:00
|
|
|
[^2]:
|
|
|
|
If you're wondering why we prefer clean commits in this project, see
|
|
|
|
e.g. [this blog post][stacked]
|
2022-12-03 14:22:02 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
[auto-bookmark]: config.md#automatic-local-bookmark-creation
|
2023-01-03 19:37:30 +00:00
|
|
|
[detached]: https://git-scm.com/docs/git-checkout#_detached_head
|
2022-12-03 14:22:02 +00:00
|
|
|
[gh]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
|
2023-01-19 16:28:00 +00:00
|
|
|
[http-auth]: https://github.com/martinvonz/jj/issues/469
|
2024-05-06 22:54:55 +00:00
|
|
|
[tut]: tutorial.md#conflicts
|
2022-12-03 14:22:02 +00:00
|
|
|
[stacked]: https://jg.gg/2018/09/29/stacked-diffs-versus-pull-requests/
|
2023-01-17 13:27:49 +00:00
|
|
|
|
|
|
|
## Using several remotes
|
|
|
|
|
2023-01-19 16:28:00 +00:00
|
|
|
It is common to use several remotes when contributing to a shared repository.
|
2023-10-24 21:09:13 +00:00
|
|
|
For example, "upstream" can designate the remote where the changes will be
|
|
|
|
merged through a pull-request while "origin" is your private fork of the
|
2024-09-12 19:20:46 +00:00
|
|
|
project.
|
2023-01-17 13:27:49 +00:00
|
|
|
|
2024-09-12 19:20:46 +00:00
|
|
|
```shell
|
|
|
|
$ jj git clone --remote upstream https://github.com/upstream-org/repo
|
|
|
|
$ cd repo
|
|
|
|
$ jj git remote add origin git@github.com:your-org/your-repo-fork
|
|
|
|
```
|
|
|
|
|
|
|
|
This will automatically setup your repository to track the main
|
|
|
|
bookmark from the upstream repository, typically `main@upstream`
|
|
|
|
or `master@upstream`.
|
|
|
|
|
|
|
|
You might want to `jj git fetch` from "upstream" and to `jj git push`
|
|
|
|
to "origin". You can configure the default remotes to fetch from and
|
|
|
|
push to in your configuration file (for example,
|
|
|
|
`.jj/repo/config.toml`):
|
2023-01-17 13:27:49 +00:00
|
|
|
|
|
|
|
```toml
|
|
|
|
[git]
|
|
|
|
fetch = "upstream"
|
|
|
|
push = "origin"
|
|
|
|
```
|
|
|
|
|
|
|
|
The default for both `git.fetch` and `git.push` is "origin".
|
2024-09-12 19:20:46 +00:00
|
|
|
|
|
|
|
If you usually work on a project from several computers, you may
|
|
|
|
configure `jj` to fetch from both repositories by default, in order to
|
|
|
|
keep your own bookmarks synchronized through your `origin` repository:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[git]
|
|
|
|
fetch = ["upstream", "origin"]
|
|
|
|
push = "origin"
|
|
|
|
```
|