CLI
monopoly is a small CLI for moving files or directories between local git repos. Full commit history carries through every move.
Synopsis
npx monopoly-repo move <source> --to <repo> [--as <path>] [--dry-run] Options
| Name | Description |
|---|---|
<source> | File or directory to move (e.g. packages/auth) |
--to <repo> | Path to a locally cloned target repository |
--as <path> | Target path inside the repo (default: source basename) |
--dry-run | Show what would happen without making changes |
-h, --help | Show help |
-v, --version | Show version |
Examples
Graduate a package out of a monorepo:
cd my-monorepo
npx monopoly-repo move packages/auth --to ../auth-service --as auth Merge a graduated repo back into a monorepo:
cd auth-service
npx monopoly-repo move auth --to ../my-monorepo --as packages/auth Hand code off from one team's repo to another:
cd platform-repo
npx monopoly-repo move src/search --to ../discovery-repo --as src/search Extract a shared utility into a shared-lib repo:
npx monopoly-repo move src/logger.ts --to ../shared Dry-run first to see what will happen:
npx monopoly-repo move packages/auth --to ../auth-service --dry-run After a move
It's up to you to integrate the code well, then git commit && git push.
If you still need the functionality in the source repo, introduce a dependency as a package or a runtime service.
monopoly does not delete from the source repo. It will print the git rm command for you to run.
Don't squash the monopoly PR when it lands on your main branch.
Undo a move
If you haven't committed yet:
cd target-repo
git merge --abort
# then manually delete the moved files If you already committed, use the standard reset flow:
git reset --soft HEAD~1 # undo the commit, keep files staged
git reset HEAD # unstage everything
git checkout . # discard the files What monopoly doesn't do
- Commit or push.
- Delete from the source repo.
- Resolve conflicts.
- Touch remotes.
Prerequisites
- git 2.22 or later
- Python 3