{"id":13533133,"url":"https://github.com/shopsys/monorepo-tools","last_synced_at":"2025-05-15T07:07:04.935Z","repository":{"id":37588130,"uuid":"121015671","full_name":"shopsys/monorepo-tools","owner":"shopsys","description":"[READ-ONLY] Tools for building and splitting monolithic repository from existing packages (with their history unchanged). This package is used for splitting our monorepo and we share it with our community as it is. We do not intend to support or develop it any further. Feel free to fork it and adjust for your own need.","archived":false,"fork":false,"pushed_at":"2025-04-14T09:06:54.000Z","size":49384,"stargazers_count":684,"open_issues_count":0,"forks_count":66,"subscribers_count":15,"default_branch":"17.0","last_synced_at":"2025-04-14T12:59:22.401Z","etag":null,"topics":["git-history","monolithic-repository","monorepo","split-monorepo"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shopsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-10T12:59:26.000Z","updated_at":"2025-04-12T00:04:02.000Z","dependencies_parsed_at":"2024-11-02T20:31:15.456Z","dependency_job_id":"84e2e36f-6ebb-46ad-b3ae-df2fab61c871","html_url":"https://github.com/shopsys/monorepo-tools","commit_stats":{"total_commits":49,"total_committers":13,"mean_commits":3.769230769230769,"dds":0.5714285714285714,"last_synced_commit":"275a31496aadc3831f799e08f7839012aa902e06"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopsys%2Fmonorepo-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopsys%2Fmonorepo-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopsys%2Fmonorepo-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopsys%2Fmonorepo-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shopsys","download_url":"https://codeload.github.com/shopsys/monorepo-tools/tar.gz/refs/heads/17.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292042,"owners_count":22046426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git-history","monolithic-repository","monorepo","split-monorepo"],"created_at":"2024-08-01T07:01:16.823Z","updated_at":"2025-05-15T07:06:59.919Z","avatar_url":"https://github.com/shopsys.png","language":"Shell","funding_links":[],"categories":["迁移工具","Shell"],"sub_categories":["Code ownership"],"readme":"# Shopsys Monorepo Tools\n\n[![Mentioned in Awesome Monorepo](https://awesome.re/mentioned-badge.svg)](https://github.com/korfuri/awesome-monorepo)\n\n**This package is used for splitting our monorepo and we share it with our community as it is. We do not intend to support or develop it any further. Feel free to fork it and adjust for your own need.**\n\nTools for building and splitting monolithic repository from existing packages.\nYou can read about pros and cons of monorepo approach on the [Shopsys Platform Blog](https://blog.shopsys.com/how-to-maintain-multiple-git-repositories-with-ease-61a5e17152e0).\n\nWe created these scripts because we couldn't find a tool that would keep the git history of subpackages unchanged.\n\nYou may need to update your `git` (tested on `2.16.1`).\n\nThis repository is maintained by [shopsys/shopsys](https://github.com/shopsys/shopsys) monorepo, information about changes is in [monorepo CHANGELOG.md](https://github.com/shopsys/shopsys/blob/master/CHANGELOG.md).\n\n## Quick start\n\n### 1. Download\n\nFirst download this repository so you can use the tools (eg. into `~/monorepo-tools`).\n\n```\ngit clone https://github.com/shopsys/monorepo-tools ~/monorepo-tools\n```\n\n### 2. Preparing an empty repository with added remotes\n\nYou have to create a new git repository for your monorepo and add all your existing packages as remotes.\nYou can add as many remotes as you want.\n\nIn this example we will prepare 3 packages from github for merging into monorepo.\n\n```\ngit init\ngit remote add main-repository http://github.com/vendor/main-repository.git\ngit remote add package-alpha http://github.com/vendor/alpha.git\ngit remote add package-beta http://github.com/vendor/beta.git\ngit fetch --all --no-tags\n```\n\n### 3. Building the monorepo\n\nThen you can build your monorepo using `monorepo_build.sh`.\nJust list the names of all your previously added remotes as arguments.\nOptionally you can specify a directory where the repository will be located by providing `\u003cremote-name\u003e:\u003csubdirectory\u003e`, otherwise remote name will be used.\n\nThe command will rewrite history of all mentioned repositories as if they were developed in separate subdirectories.\n\nOnly branches `master` will be merged together, other branches will be kept only from first package to avoid possible branch name conflicts.\n\n```\n~/monorepo-tools/monorepo_build.sh \\\n    main-repository package-alpha:packages/alpha package-beta:packages/beta\n```\n\nThis may take a while, depending on the size of your repositories.\n\nNow your `master` branch should contain all packages in separate directories. For our example it would mean:\n\n- **main-repository/** - contains repository _vendor/main-repository_\n- **packages/**\n    - **alpha/** - contains repository _vendor/alpha_\n    - **beta/** - contains repository _vendor/beta_\n\n### 4. Splitting into original repositories\n\nYou should develop all your packages in this repository from now on.\n\nWhen you made your changes and would like to update the original repositories use `monorepo_split.sh` with the same arguments as before.\n\n```\n~/monorepo-tools/monorepo_split.sh \\\n    main-repository package-alpha:packages/alpha package-beta:packages/beta\n```\n\nThis will push all relevant changes into all of your remotes.\nIt will split and push your `master` branch along with all tags you added in this repository.\nOther branches are not pushed.\n\nIt may again take a while, depending on the size of your monorepo.\n\n**_Note:_**  \n_The commits in the split repositories should be identical to those from the original repo, keeping the git history intact._\n_Thus, if you have checked out the original `master` previously, you should be able to fast-forward to the new version after splitting._  \n_The only known exception is a signed commit (note that GitHub signs commits made via its web UI by default)._\n_If you have signed commits in your original repository, the split commits will NOT be signed._\n_This will prevent `monorepo_split.sh` from pushing the unsigned commits to the remote._  \n_To overcome this you can add [the `--force` flag](https://git-scm.com/docs/git-push#git-push--f) to the `git push` calls in the script, but it may cause unforeseen consequences if you're not sure what you're doing._\n\n### Add a new package into the monorepo\n\nWhen you have the monorepo, you may find a reason for adding a new package after some time you already use the monorepo.\nIn this case, don't use `monorepo_build.sh`, but do following steps:\n\n- Create a new repository, for example, _vendor/gamma_\n- Add remote into the monorepo `git remote add package-gamma http://github.com/vendor/gamma.git`\n- Create a new directory in the monorepo **packages/gamma**\n- Add the code and commit it\n- Use split tool with the new package\n    ```\n    ~/monorepo-tools/monorepo_split.sh \\\n        main-repository package-alpha:packages/alpha package-beta:packages/beta package-gamma:packages/gamma\n    ```\n\n## Reference\n\nThis is just a short description and usage of all the tools in the package.\nFor detailed information go to the scripts themselves and read the comments.\n\n### [monorepo_build.sh](./monorepo_build.sh)\n\nBuild monorepo from specified remotes. The remotes must be already added to your repository and fetched.\n\nUsage: `monorepo_build.sh \u003cremote-name\u003e[:\u003csubdirectory\u003e] \u003cremote-name\u003e[:\u003csubdirectory\u003e] ...`\n\n### [monorepo_split.sh](./monorepo_split.sh)\n\nSplit monorepo built by `monorepo_build.sh` and push all `master` branches along with all tags into specified remotes.\n\nUsage: `monorepo_split.sh \u003cremote-name\u003e[:\u003csubdirectory\u003e] \u003cremote-name\u003e[:\u003csubdirectory\u003e] ...`\n\n### [monorepo_add.sh](./monorepo_add.sh)\n\nAdd 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.\n\nUsage: `monorepo_add.sh \u003cremote-name\u003e[:\u003csubdirectory\u003e] \u003cremote-name\u003e[:\u003csubdirectory\u003e] ...`\n\n### [rewrite_history_into.sh](./rewrite_history_into.sh)\n\nRewrite git history (even tags) so that all filepaths are in a specific subdirectory.\n\nUsage: `rewrite_history_into.sh \u003csubdirectory\u003e [\u003crev-list-args\u003e]`\n\n### [rewrite_history_from.sh](./rewrite_history_from.sh)\n\nRewrite 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.\n\nUsage: `rewrite_history_from.sh \u003csubdirectory\u003e [\u003crev-list-args\u003e]`\n\n### [original_refs_restore.sh](./original_refs_restore.sh)\n\nRestore original git history after rewrite.\n\nUsage: `original_refs_restore.sh`\n\n### [original_refs_wipe.sh](./original_refs_wipe.sh)\n\nWipe original git history after rewrite.\n\nUsage: `original_refs_wipe.sh`\n\n### [load_branches_from_remote.sh](./load_branches_from_remote.sh)\n\nDelete all local branches and create all non-remote-tracking branches of a specified remote.\n\nUsage: `load_branches_from_remote.sh \u003cremote-name\u003e`\n\n### [tag_refs_backup.sh](./tag_refs_backup.sh)\n\nBackup tag refs into `refs/original-tags/`\n\nUsage: `tag_refs_backup.sh`\n\n### [tag_refs_move_to_original.sh](./tag_refs_move_to_original.sh)\n\nMove tag refs from `refs/original-tags/` into `refs/original/`\n\nUsage: `tag_refs_move_to_original.sh`\n\n## Contributing\n\nThank you for your contributions to Shopsys Monorepo Tools package.\nTogether we are making Shopsys Platform better.\n\nThis repository is READ-ONLY.\nIf you want to [report issues](https://github.com/shopsys/shopsys/issues/new) and/or send [pull requests](https://github.com/shopsys/shopsys/compare),\nplease use the main [Shopsys repository](https://github.com/shopsys/shopsys).\n\nPlease, check our [Contribution Guide](https://github.com/shopsys/shopsys/blob/master/CONTRIBUTING.md) before contributing.\n\n## Support\n\nWhat to do when you are in troubles or need some help?\nThe best way is to join our [Slack](https://join.slack.com/t/shopsysframework/shared_invite/zt-11wx9au4g-e5pXei73UJydHRQ7nVApAQ).\n\nIf you want to [report issues](https://github.com/shopsys/shopsys/issues/new), please use the main [Shopsys repository](https://github.com/shopsys/shopsys).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopsys%2Fmonorepo-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshopsys%2Fmonorepo-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopsys%2Fmonorepo-tools/lists"}