yisraeldov / composer-subtree-plugin
Composer plugin for safer git subtree workflows
Package info
github.com/yisraeldov/composer-subtree-plugin
Type:composer-plugin
pkg:composer/yisraeldov/composer-subtree-plugin
Requires
- php: ^8.2
- composer-plugin-api: ^2.2
Requires (Dev)
- composer/composer: ^2.9
- friendsofphp/php-cs-fixer: ^3.95
- php-parallel-lint/php-parallel-lint: ^1.4
- phpactor/phpactor: ^2025.03@dev
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2026-04-28 12:18:33 UTC
README
⚠️ 🤖 💩 Made with lots of AI help, so use at your own risk
composer-subtree-plugin
A Composer plugin that adds practical Git subtree commands to your PHP project.
Implemented today:
composer subtree:addcomposer subtree:pullcomposer subtree:push
What this project is
composer-subtree-plugin helps you manage subtree-based package workflows from Composer commands.
It stores subtree metadata on type=path repository entries in
composer.json.repositories[].composer-subtree-plugin and uses those
definitions for pull/push operations.
Why use this
This plugin is useful when your team has internal libraries that were previously pulled in through Composer vcs repositories, and that setup is causing friction in CI and deployment.
Common pain points with vcs internal dependencies:
- CI and deploy jobs depend on external repository availability and auth at install time.
- Build environments need extra SSH/token setup just to resolve private package sources.
- Reproducibility can become harder when dependency resolution and Git access are tightly coupled.
How this plugin helps:
- You vendor internal libraries as Git subtrees directly in your main repository.
- Composer installs from local code paths already present in the checkout.
- CI and deploy pipelines become simpler because subtree sync is an explicit step (
subtree:pull/subtree:push) instead of an implicit runtime dependency fetch.
Requirements
- PHP
^8.2 - Composer plugin API
^2.2 gitwithgit subtreeavailable
Installation
Install in the consumer project:
composer require yisraeldov/composer-subtree-plugin --dev
If your Composer setup requires explicit plugin approval, add:
{
"config": {
"allow-plugins": {
"yisraeldov/composer-subtree-plugin": true
}
}
}
Configuration format
Subtrees are configured on type=path repository entries:
{
"repositories": [
{
"type": "path",
"url": "packages/pcre",
"composer-subtree-plugin": {
"remote": "https://github.com/composer/pcre.git",
"branch": "main",
"squash": false
}
}
]
}
Fields:
url(string): local subtree directory (path repository URL)remote(string): upstream repository URLbranch(string): upstream branchsquash(bool, optional): whether pull/add uses--squash(defaults tofalse)
Day-to-day usage
1) Add a new subtree
composer subtree:add <upstream-url> <upstream-branch> [prefix] [--squash]
Example:
composer subtree:add https://github.com/composer/pcre.git main
What it does:
- Runs
git subtree add --prefix=... <remote> <branch> [--squash] - Ensures
composer.json.repositoriescontains a path repository entry for the subtree prefix - Writes/updates subtree metadata at
repositories[].composer-subtree-plugin
Notes:
- If
prefixis omitted, default ispackages/<repo-name>. - Target selection is path-based (for example
packages/pcre) orall. - If the git command fails, config is not persisted.
2) Pull subtree updates
composer subtree:pull [target]
targetcan be a subtree path target (for examplepackages/pcre) orall.- If omitted, it behaves like
all.
Examples:
composer subtree:pull packages/pcre composer subtree:pull all composer subtree:pull
What it does per subtree:
git fetch <remote> <branch>git subtree pull --prefix=<prefix> <remote> <branch> [--squash]
3) Push subtree updates
composer subtree:push [target]
targetcan be a subtree path target orall.- If omitted, it behaves like
all.
Examples:
composer subtree:push packages/pcre composer subtree:push all composer subtree:push
What it does per subtree:
git subtree push --prefix=<prefix> <remote> <branch>
Current scope (implemented)
This plugin currently provides:
- Add subtree + persist subtree config
- Pull one/all configured subtrees
- Push one/all configured subtrees
No other subtree commands or update hooks are documented here because they are not implemented yet.