I am involved in a project with two separate repositories that we will soon be combining into a monorepo. Lerna's import
command will be very helpful in this regard, so we will keep the projects' histories.
However, there are currently some in-progress feature branches in the original repositories that likely won't be ready when we move to the monorepo. It's my understanding that lerna import
will only pull in the currently checked out branch from the source repo - is that correct?
So I was wondering if there was a way to do the import again, but only pull in commits that have been made since the last import?
That way, the teams working on the feature branches can merge to the develop
branch once they're ready and we can bring that over into the monorepo.
Alternatively, are there strategies out there for dealing with this scenario?
Or am I going to have to wait until everything is merged to develop
before doing the lerna import
?
Thanks!
In a single, monolithic repository, also known as a monorepo, you keep all your application and microservice code in the same source code repository (usually Git). Typically, teams split the code of various app components into subfolders and use Git workflow for new features or bug fixes.
Existing packages You can use lerna import <package> to transfer an existing package into your Lerna repository; this command will preserve the commit history. lerna import <package> takes a local path rather than a URL. In this case you will need to have the repo you wish to link to on your file system.
Google, Facebook, Microsoft, Uber, Airbnb, and Twitter all employ very large monorepos with varying strategies to scale build systems and version control software with a large volume of code and daily changes.
A monorepo is simply the practice of placing multiple different projects that are related in some way into the same repository. The biggest benefit is that you do not need to worry about version mismatch issues between the different pieces of your project.
Using the answer by @Doğancan Arabacı and comment by @Matt Mazzola. I was able to do this for myself, but I've added my own answer with a few more details to try and give a clearer explanation.
I also faced this problem as lerna import
will only allow you to import once if the directory exists you can’t import. See code here.
The lerna import
command takes all the commits from your original repository, reverses and replays them. However there’s no way to replay these from when branches diverge (as you might with the git rebase --onto
command). See here I get the feeling that you could possibly achieve it using git rebase
or using a similar technique to pick out where branches diverge to extend the lerna import
command. I also get the feeling that might get messy or take while so the simple way that currently exists is:
For each branch you wish to import:
From the original repo (referred to as original
:
git checkout -b lerna-export
packages/original
something like: mkdir packages && mkdir packages/original
git mv -k * ./packages/original
- you may have to copy over any files that aren’t pickedThen from the Lerna repo:
git remote add original ###url of repo###
git checkout -b orignal-import
git merge original/lerna-export --allow-unrelated-histories
git push
After all branches imported, you may want to remove the second remote once all the branches are imported: git remove rm original
I had some issues with the security on our BitBucket instance as I was pushing commits by other authors so I had to rewrite the git history with git filter-branch
, but that doesn’t seem totally related to the question to provide details of it.
I'm not sure what lerna is doing underhood but there is manual way of doing it with git. We did similar thing in past for 8-10 repositories.
Let's assume we have MonoRepo and TargetRepo
You can repeat steps 3-4 whenever you want, after a few commits, do everything at one day and move to mono repo etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With