- Notifications
You must be signed in to change notification settings - Fork2
[READ-ONLY] Tools for building and splitting monolithic repository from existing packages (with their history unchanged). This package is used for splitting our monorepo into various repositories for distribution.
License
embeddedartistry/monorepo-tools
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This package is used for splitting the Embedded Artistry monorepo and we share it with our community as it is. We are willing to consider issues and pull requests, but this project's primary purpose is to serve our own use case.
Tools for building and splitting monolithic repository from existing packages.
We created these scripts because we couldn't find a tool that would keep the git history of subpackages unchanged.
You may need to update yourgit (tested on2.16.1).
This repository is maintained inembeddedartistry/monorepo.
Primary differences from the originalshopsys/monorepo-tools:
- Uses git filter-repo, resulting in drastically improved performance
- Supports git-lfs files
- Works with
mainbranch by default - Provides an option for overriding which branch will be merged in or split out
First download this repository so you can use the tools (eg. into~/monorepo-tools).
git clone https://github.com/embeddedartistry/monorepo-tools ~/monorepo-toolsYou have to create a new git repository for your monorepo and add all your existing packages as remotes.You can add as many remotes as you want.
In this example we will prepare 3 packages from github for merging into monorepo.
git initgit remote add main-repository http://github.com/vendor/main-repository.gitgit remote add package-alpha http://github.com/vendor/alpha.gitgit remote add package-beta http://github.com/vendor/beta.gitgit fetch --all --no-tagsThen you can build your monorepo usingmonorepo_build.sh.Just list the names of all your previously added remotes as arguments.Optionally you can specify a directory where the repository will be located by providing<remote-name>:<subdirectory>, otherwise remote name will be used.
The command will rewrite history of all mentioned repositories as if they were developed in separate subdirectories.
Only branchesmain will be merged together, other branches will be kept only from first package to avoid possible branch name conflicts.
~/monorepo-tools/monorepo_build.sh \ main-repository package-alpha:packages/alpha package-beta:packages/betaThis may take a while, depending on the size of your repositories.
Now yourmain branch should contain all packages in separate directories. For our example it would mean:
- main-repository/ - contains repositoryvendor/main-repository
- packages/
- alpha/ - contains repositoryvendor/alpha
- beta/ - contains repositoryvendor/beta
You should develop all your packages in this repository from now on.
When you made your changes and would like to update the original repositories usemonorepo_split.sh with the same arguments as before.
~/monorepo-tools/monorepo_split.sh \ main-repository package-alpha:packages/alpha package-beta:packages/betaThis will push all relevant changes into all of your remotes.It will split and push yourmain branch along with all tags you added in this repository.Other branches are not pushed.
It may again take a while, depending on the size of your monorepo.
Note:
The commits in the split repositories should be identical to those from the original repo, keeping the git history intact.Thus, if you have checked out the originalmain previously, you should be able to fast-forward to the new version after splitting.
The only known exception is a signed commit (note that GitHub signs commits made via its web UI by default).If you have signed commits in your original repository, the split commits will NOT be signed.This will preventmonorepo_split.sh from pushing the unsigned commits to the remote.
To overcome this you can addthe--force flag to thegit push calls in the script, but it may cause unforeseen consequences if you're not sure what you're doing.
When you have the monorepo, you may find a reason for adding a new package after some time you already use the monorepo.In this case, don't usemonorepo_build.sh, but do following steps:
- Create a new repository, for example,vendor/gamma
- Add remote into the monorepo
git remote add package-gamma http://github.com/vendor/gamma.git - Create a new directory in the monorepopackages/gamma
- Add the code and commit it
- Use split tool with the new package
~/monorepo-tools/monorepo_split.sh \ main-repository package-alpha:packages/alpha package-beta:packages/beta package-gamma:packages/gamma
This is just a short description and usage of all the tools in the package.For detailed information go to the scripts themselves and read the comments.
Build monorepo from specified remotes. The remotes must be already added to your repository and fetched.
Usage:monorepo_build.sh <remote-name>[:<subdirectory>][:<branch>] <remote-name>[:<subdirectory>][:<branch>] ...
Split monorepo built bymonorepo_build.sh and push allmain branches along with all tags into specified remotes.
Usage:monorepo_split.sh <remote-name>[:<subdirectory>][:<branch>] <remote-name>[:<subdirectory>][:<branch>] ...
Add repositories to an existing monorepo from specified remotes. The remotes must be already added to your repository and fetched. Only main branch will be added from each repo.
Usage:monorepo_add.sh <remote-name>[:<subdirectory>][:<branch>] <remote-name>[:<subdirectory>][:<branch>] ...
Rewrite git history (even tags) so that all filepaths are in a specific subdirectory.
Usage:rewrite_history_into.sh <subdirectory> [<refs to keep>]
Rewrite git history (even tags) so that only commits that made changes in a subdirectory are kept and rewrite all filepaths as if it was root.
Usage:rewrite_history_from.sh <subdirectory> [<refs to export]
Restore original git history after rewrite.
Usage:original_refs_restore.sh
Wipe original git history after rewrite.
Usage:original_refs_wipe.sh
Delete all local branches and create all non-remote-tracking branches of a specified remote.
Usage:load_branches_from_remote.sh <remote-name>
Backup tag refs intorefs/original-tags/
Usage:tag_refs_backup.sh
Move tag refs fromrefs/original-tags/ intorefs/tags/
Usage:tag_refs_restore.sh
This repository is READ-ONLY.
You can report issues here, but it is better toreport issues and/or sendpull requests in the mainembeddedartistry/monorepo repository.
About
[READ-ONLY] Tools for building and splitting monolithic repository from existing packages (with their history unchanged). This package is used for splitting our monorepo into various repositories for distribution.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Shell53.7%
- Python46.3%