@wetoria/git-subtree-cli
v1.2.0
Published
Git Subtree 管理工具 - 支持交互式菜单和批量操作
Downloads
14
Maintainers
Readme
@wetoria/git-subtree-cli
Git Subtree 管理工具 - 支持交互式菜单和批量操作
功能特性
- 🎯 交互式 CLI 菜单 - 友好的命令行界面
- 📦 批量操作 - 支持批量添加 remote、批量推送/拉取
- 🔍 状态检查 - 显示 remote 是否存在
- 🎨 彩色输出 - 清晰的视觉反馈
- ⚙️ 灵活配置 - 通过 JSON 配置文件管理多个 subtree
安装
全局安装
npm install -g @wetoria/git-subtree-cli
# 或
pnpm add -g @wetoria/git-subtree-cli
# 或
yarn global add @wetoria/git-subtree-cli项目内使用(推荐)
npm install -D @wetoria/git-subtree-cli
# 或
pnpm add -D @wetoria/git-subtree-cli然后在 package.json 中添加脚本:
{
"scripts": {
"subtree": "git-subtree"
}
}使用 npx(无需安装)
npx @wetoria/git-subtree-cli使用方法
快速开始(推荐)
使用 init 命令快速初始化:
# 使用 npx(无需安装)
npx @wetoria/git-subtree-cli init
# 或全局安装后
npm install -g @wetoria/git-subtree-cli
git-subtree initinit 命令会自动:
- ✅ 创建
.git-subtree-config.json配置文件(如果不存在) - ✅ 在
package.json中添加subtree脚本(如果不存在)
手动配置
1. 创建配置文件
在项目根目录创建 .git-subtree-config.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. 运行工具
git-subtree
# 或
gitsbt
# 或
pnpm subtree
# 或
npm run subtree3. 选择操作
工具会显示交互式菜单:
╔═══════════════════════════════════════╗
║ 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. 退出配置说明
配置文件字段
name: subtree 名称(用于显示)remote: 远程仓库 URLremoteName: Git remote 名称branch: 分支名称(如 main, master)prefix: 本地路径前缀description: 描述信息(可选)
配置文件位置
工具会按以下顺序查找配置文件:
- 项目根目录的
.git-subtree-config.json - 项目根目录的
git-subtree-config.json - 当前目录的
.git-subtree-config.json - 当前目录的
git-subtree-config.json
功能说明
1. 添加/更新 remote
添加或更新 Git remote,用于 subtree 操作。
2. 添加 subtree
将远程仓库添加为 subtree(首次添加时使用)。
3. 拉取 subtree
从远程仓库拉取最新更改。
4. 推送 subtree
将本地更改推送到远程仓库。
5. 批量操作
批量执行操作,适用于管理多个 subtree。
示例
示例 1: 添加新的 subtree
- 在配置文件中添加配置
- 运行
git-subtree - 选择 "1. 添加/更新 remote"
- 选择 "2. 添加 subtree"
示例 2: 批量拉取所有 subtree
- 运行
git-subtree - 选择 "5. 批量操作所有"
- 选择 "3. 批量拉取所有 subtree"
要求
- Node.js >= 18.0.0
- Git(已安装并配置)
License
MIT
Author
Wetoria
