Git Subtree 管理工具 - 支持交互式菜单和批量操作
npm install @wetoria/git-subtree-cliGit Subtree 管理工具 - 支持交互式菜单和批量操作
- 🎯 交互式 CLI 菜单 - 友好的命令行界面
- 📦 批量操作 - 支持批量添加 remote、批量推送/拉取
- 🔍 状态检查 - 显示 remote 是否存在
- 🎨 彩色输出 - 清晰的视觉反馈
- ⚙️ 灵活配置 - 通过 JSON 配置文件管理多个 subtree
``bash`
npm install -g @wetoria/git-subtree-cli或
pnpm add -g @wetoria/git-subtree-cli或
yarn global add @wetoria/git-subtree-cli
`bash`
npm install -D @wetoria/git-subtree-cli或
pnpm add -D @wetoria/git-subtree-cli
然后在 package.json 中添加脚本:
`json`
{
"scripts": {
"subtree": "git-subtree"
}
}
`bash`
npx @wetoria/git-subtree-cli
使用 init 命令快速初始化:
`bash使用 npx(无需安装)
npx @wetoria/git-subtree-cli init
init 命令会自动:
- ✅ 创建 .git-subtree-config.json 配置文件(如果不存在)
- ✅ 在 package.json 中添加 subtree 脚本(如果不存在)$3
#### 1. 创建配置文件
在项目根目录创建
.git-subtree-config.json 文件:`json
{
"subtree-name": {
"name": "subtree-name",
"remote": "https://github.com/user/repo.git",
"remoteName": "remote-name",
"branch": "main",
"prefix": "path/to/subtree",
"description": "描述信息"
},
"another-subtree": {
"name": "another-subtree",
"remote": "https://github.com/user/another-repo.git",
"remoteName": "another-remote",
"branch": "main",
"prefix": "path/to/another",
"description": "另一个 subtree 的描述"
}
}
`#### 2. 运行工具
`bash
git-subtree
或
gitsbt
或
pnpm subtree
或
npm run subtree
`#### 3. 选择操作
工具会显示交互式菜单:
`
╔═══════════════════════════════════════╗
║ Git Subtree 管理工具 ║
╚═══════════════════════════════════════╝📦 Subtree 配置列表:
1. subtree-name [✓]
描述: 描述信息
路径: path/to/subtree
Remote: remote-name -> https://github.com/user/repo.git
分支: main
操作选项:
1. 添加/更新 remote
2. 添加 subtree
3. 拉取 subtree
4. 推送 subtree
5. 批量操作所有
0. 退出
`配置说明
$3
-
name: subtree 名称(用于显示)
- remote: 远程仓库 URL
- remoteName: Git remote 名称
- branch: 分支名称(如 main, master)
- prefix: 本地路径前缀
- description: 描述信息(可选)$3
工具会按以下顺序查找配置文件:
1. 项目根目录的
.git-subtree-config.json
2. 项目根目录的 git-subtree-config.json
3. 当前目录的 .git-subtree-config.json
4. 当前目录的 git-subtree-config.json功能说明
$3
添加或更新 Git remote,用于 subtree 操作。
$3
将远程仓库添加为 subtree(首次添加时使用)。
$3
从远程仓库拉取最新更改。
$3
将本地更改推送到远程仓库。
$3
批量执行操作,适用于管理多个 subtree。
示例
$3
1. 在配置文件中添加配置
2. 运行
git-subtree
3. 选择 "1. 添加/更新 remote"
4. 选择 "2. 添加 subtree"$3
1. 运行
git-subtree`- Node.js >= 18.0.0
- Git(已安装并配置)
MIT
Wetoria