Combining two unrelated Jujutsu repos

Aug 19, 2025, 2:44 AM
Δ
Aug 19, 2025, 2:55 AM
Jujutsu SiteV2

Will Richardson has a handy post suggesting that you can merge Jujutsu repos. Let's do that on purpose! (Because I want my website front end and posts to live in the same place now.)

Before doing this, it's probably a good idea to make sure the histories of both repos are in good states; for example, if one repo has a massive files or messy changes or leaked credentials, that will allll get brought over into its new home, and will likely be harder to manage after merging.

1. Set up repo 2 as a remote

jj git remote add other-remote <URL>

The first step is to convince the current repo that it's had a second source this whole time that's just wildly divergent. Here, we're naming that remote other-remote just to keep things clear. You can theoretically add any arbitrary repository as a remote, and Jujutsu/Git will have to figure out how to reconcile that.

2. Fetch all that remote's stuff!

jj git fetch --remote other-remote

Fetching the remote brings in all of the history and data from that remote into your local repo.

Branches are disambiguated with an @, so main@origin (origin is the usual "default remote" name) points to your normal main branch, while main@other-remote points to the main branch (if there's one named that) of the second remote we just added.

3. Create a merge commit

jj new main main@other-remote

jj new <change_id> <change_id> makes a change with the two given changes as its parents—in other words, a "merge" of those changes. With this line, we're merging main (based on the origin remote) with main@other-remote to bring the two codebases together.

4. Remove the spare remote

jj git remote remove other-remote

It's important to get rid of the remote of the repo you're folding in before you do any pushing! Otherwise, both repos to get the wacky consequences of your cursed commit wrangling.

5. Cleanup

The new merge change we made in step 3 may or may not need a bunch of cleanup/conflict resolution. Whatever you do here determines exactly how the two repos get combined.

Aside from post-merge cleanup, It might be helpful to add some tweaks before the merge commit. For example, I did jj new --after main@other-remote and tweaked the .gitignore and README.md files, and also shoved all of the incoming code into its own subdirectory to avoid any immediate conflicts. That let me ease in to figuring out the fine details of reorganizing things without having to know it all in advance.

6. Push it

Once you're content with the state of things (and maybe a few new commits deep into the happy union just to be safe), and you've made sure to delete remotes you don't want to push to, you can bump up the main branch to the latest change and push it.

Done!