| 1 |
# Multiple remotes |
| 2 |
|
| 3 |
When using multiple [remote repositories], how you configure them in Jujutsu |
| 4 |
depends on your workflow and the role each remote plays. |
| 5 |
|
| 6 |
The setup varies based on whether you are contributing to an upstream project, |
| 7 |
or integrating changes from another repository. |
| 8 |
|
| 9 |
[remote repositories]: ../glossary.md#remote |
| 10 |
|
| 11 |
## Nomenclature |
| 12 |
|
| 13 |
A remote named `origin` is one you have write-access to and is usually where you |
| 14 |
push changes. |
| 15 |
|
| 16 |
A remote named `upstream` is the more well-known repository. You may not be able |
| 17 |
to push to this repository. |
| 18 |
|
| 19 |
The trunk in each repository is assumed to be `main`, so the remote bookmarks |
| 20 |
are `main@origin` and `main@upstream`. |
| 21 |
|
| 22 |
## Contributing upstream with a GitHub-style fork |
| 23 |
|
| 24 |
This is a GitHub-style fork used to contribute to the upstream repository. |
| 25 |
`upstream` is the canonical upstream remote, and `origin` is where you push |
| 26 |
contributions, most likely so you can open pull requests. |
| 27 |
|
| 28 |
Actions you might take: |
| 29 |
|
| 30 |
- Fetch from `upstream` to get the latest changes. |
| 31 |
- Push `main` to `origin` to keep it up-to-date. |
| 32 |
- Push `my-feature` to `origin`, then open a pull request to `upstream`. |
| 33 |
|
| 34 |
To support this scenario, you should: |
| 35 |
|
| 36 |
- Track `main@upstream` so your local `main` branch is updated whenever you |
| 37 |
fetch from `upstream`. |
| 38 |
- Track `main@origin` so when you `jj git push`, your fork's `main` branch is |
| 39 |
updated. |
| 40 |
- Set `main@upstream` as the `trunk()` revset alias so it is immutable. |
| 41 |
|
| 42 |
```shell |
| 43 |
# Fetch from both remotes by default |
| 44 |
$ jj config set --repo git.fetch '["upstream", "origin"]' |
| 45 |
|
| 46 |
# Push only to the fork by default |
| 47 |
$ jj config set --repo git.push origin |
| 48 |
|
| 49 |
# Track both remote bookmarks |
| 50 |
$ jj bookmark track main |
| 51 |
|
| 52 |
# The upstream repository defines the trunk |
| 53 |
$ jj config set --repo 'revset-aliases."trunk()"' main@upstream |
| 54 |
``` |
| 55 |
|
| 56 |
## Maintaining an independent repository that integrates changes from upstream |
| 57 |
|
| 58 |
This is a repository that was originally cloned from upstream, but now contains |
| 59 |
changes in its `main` branch that are not upstream and might never be |
| 60 |
contributed back. |
| 61 |
|
| 62 |
- `origin` is the repository you are working in. |
| 63 |
- `upstream` is the repository you periodically integrate changes from. |
| 64 |
|
| 65 |
Actions you might take: |
| 66 |
|
| 67 |
- Fetch from `origin` to get the latest changes. |
| 68 |
- Push bookmarks to `origin`. |
| 69 |
- Merge pull requests into `main@origin`. |
| 70 |
- Periodically fetch from `main@upstream` and merge, rebase, or duplicate its |
| 71 |
changes into `main@origin`. |
| 72 |
|
| 73 |
To support this scenario, you should: |
| 74 |
|
| 75 |
- Track only `main@origin` so your local `main` branch is updated whenever you |
| 76 |
fetch from `origin`, and so you can push to it if necessary. |
| 77 |
- _Do not_ track `main@upstream`. |
| 78 |
- Set `main@origin` as the `trunk()` revset alias so it is immutable. |
| 79 |
|
| 80 |
```shell |
| 81 |
# Fetch from origin or both remotes by default |
| 82 |
$ jj config set --repo git.fetch '["origin"]' |
| 83 |
# or: jj config set --repo git.fetch '["upstream", "origin"]' |
| 84 |
|
| 85 |
# Push only to origin by default |
| 86 |
$ jj config set --repo git.push origin |
| 87 |
|
| 88 |
# Track only the origin bookmark |
| 89 |
$ jj bookmark track main --remote=origin |
| 90 |
$ jj bookmark untrack main --remote=upstream |
| 91 |
|
| 92 |
# The origin repository defines the trunk |
| 93 |
$ jj config set --repo 'revset-aliases."trunk()"' main@origin |
| 94 |
``` |
| 95 |
|
| 96 |
## Other workflows |
| 97 |
|
| 98 |
Other workflows may be supported. Some general guidance for this: |
| 99 |
|
| 100 |
- Set `trunk()` to be the remote bookmark you usually rebase upon. If you always |
| 101 |
rebase against upstream, set it to `main@upstream`. |
| 102 |
|
| 103 |
- Tracking a remote bookmark `main@origin` means it and `main` represent the |
| 104 |
same branch. When one moves, the other should move with it. If you want them to |
| 105 |
_automatically_ move together, you should track the remote bookmark. If not, do |
| 106 |
not track it. |
| 107 |
|
| 108 |
If you have a workflow that is not well-supported, discussion is welcome in |
| 109 |
[Discord]. There is also an [open discussion] for enhancing how bookmark |
| 110 |
tracking works. |
| 111 |
|
| 112 |
[Discord]: https://discord.gg/dkmfj3aGQN |
| 113 |
[open discussion]: https://github.com/jj-vcs/jj/issues/7072 |