Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.

Shopsys Monorepo Tools

Mentioned in Awesome Monorepo

Tools for building and splitting monolithic repository from existing packages. You can read about pros and cons of monorepo approach on the Shopsys Framework Blog.

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 your git (tested on 2.16.1).

This repository is maintained by shopsys/shopsys monorepo, information about changes is in monorepo

Quick start

1. Download

First download this repository so you can use the tools (eg. into ~/monorepo-tools).

git clone ~/monorepo-tools

2. Preparing an empty repository with added remotes

You 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 init
git remote add main-repository
git remote add package-alpha
git remote add package-beta
git fetch --all --no-tags

3. Building the monorepo

Then you can build your monorepo using 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 branches master will be merged together, other branches will be kept only from first package to avoid possible branch name conflicts.

~/monorepo-tools/ \
    main-repository package-alpha:packages/alpha package-beta:packages/beta

This may take a while, depending on the size of your repositories.

Now your master branch should contain all packages in separate directories. For our example it would mean:

  • main-repository/ - contains repository vendor/main-repository
  • packages/
    • alpha/ - contains repository vendor/alpha
    • beta/ - contains repository vendor/beta

4. Splitting into original repositories

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 use with the same arguments as before.

~/monorepo-tools/ \
    main-repository package-alpha:packages/alpha package-beta:packages/beta

This will push all relevant changes into all of your remotes. It will split and push your master 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.

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 original master 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 prevent from pushing the unsigned commits to the remote.
To overcome this you can add the --force flag to the git push calls in the script, but it may cause unforeseen consequences if you're not sure what you're doing.

Add a new package into the monorepo

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 use, but do following steps:

  • Create a new repository, for example, vendor/gamma
  • Add remote into the monorepo git remote add package-gamma
  • Create a new directory in the monorepo packages/gamma
  • Add the code and commit it
  • Use split tool with the new package
    ~/monorepo-tools/ \
        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: <remote-name>[:<subdirectory>] <remote-name>[:<subdirectory>] ...

Split monorepo built by and push all master branches along with all tags into specified remotes.

Usage: <remote-name>[:<subdirectory>] <remote-name>[:<subdirectory>] ...

Add repositories to an existing monorepo from specified remotes. The remotes must be already added to your repository and fetched. Only master branch will be added from each repo.

Usage: <remote-name>[:<subdirectory>] <remote-name>[:<subdirectory>] ...

Rewrite git history (even tags) so that all filepaths are in a specific subdirectory.

Usage: <subdirectory> [<rev-list-args>]

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: <subdirectory> [<rev-list-args>]

Restore original git history after rewrite.


Wipe original git history after rewrite.


Delete all local branches and create all non-remote-tracking branches of a specified remote.

Usage: <remote-name>

Backup tag refs into refs/original-tags/


Move tag refs from refs/original-tags/ into refs/original/



Thank you for your contributions to Shopsys Monorepo Tools package. Together we are making Shopsys Framework better.

This repository is READ-ONLY. If you want to report issues and/or send pull requests, please use the main Shopsys repository.

Please, check our Contribution Guide before contributing.


What to do when you are in troubles or need some help? Best way is to contact us on our Slack

If you want to report issues, please use the main Shopsys repository.


[READ-ONLY] Tools for building and splitting monolithic repository from existing packages (with their history unchanged)





No packages published


You can’t perform that action at this time.