tanyu_mg
v1.0.1
Published
A global npm package for simplified git operations with proxy support
Maintainers
Readme
mg-git-cli
一个带代理支持的全局 Git 命令行工具,简化代码仓库的日常操作。
功能特性
- 代理支持 - 自动配置 HTTP/HTTPS 代理,无需手动设置环境变量
- 简化操作 -
mg pull/mg push快速同步代码 - 仓库管理 -
mg cd快速切换工作目录 - 批量克隆 -
mg clone自动克隆到指定目录并添加到管理列表 - 状态查看 -
mg status查看单个或所有仓库的状态
安装
# 全局安装
pnpm install -g .
# 或
npm install -g .配置
设置代理
# 同时设置 HTTP 和 HTTPS 代理
mg config set proxy=http://127.0.0.1:7897
# 分别设置
mg config set http-proxy=http://127.0.0.1:7897
mg config set https-proxy=http://127.0.0.1:7897设置仓库根目录
mg config set repos-path=D:/code/repos查看配置
mg config list命令使用
mg pull
从远程仓库拉取代码:
mg pull
mg pull -r origin # 指定远程仓库mg push
推送代码到远程仓库:
mg push
mg push -f # 强制推送
mg push --no-set-upstream # 不设置上游分支mg clone
克隆远程仓库并自动添加到管理列表:
mg clone https://github.com/user/repo.git
mg clone https://github.com/user/repo.git -d D:/code/repo
mg clone https://github.com/user/repo.git --depth 1 # 浅克隆
mg clone https://github.com/user/repo.git -b dev # 克隆指定分支mg cd
切换到已添加的仓库目录(需要先配置 shell 集成):
# 首次使用需要初始化 shell 集成
mg init
# 然后使用
mg-cd repo-name
# 或
mg cd # 查看所有可用仓库mg status
查看仓库状态:
mg status # 查看当前仓库状态
mg status -a # 查看所有仓库状态
mg st # 简写Shell 集成
PowerShell
mg init --shell powershell然后将输出的内容添加到你的 PowerShell Profile 中:
notepad $PROFILEBash/Zsh
mg init --shell bash
# 或
mg init --shell zsh然后将输出的内容添加到 ~/.bashrc 或 ~/.zshrc 中。
配置文件
配置文件存储位置:
- Windows:
%APPDATA%\mg-git-cli\config.json - macOS/Linux:
~/.config/mg-git-cli/config.json
示例
# 1. 设置代理
mg config set proxy=http://127.0.0.1:7897
# 2. 设置仓库目录
mg config set repos-path=D:/workspace
# 3. 克隆仓库
mg clone https://github.com/user/project.git
# 4. 查看状态
mg status
# 5. 初始化 shell 集成后切换目录
mg-cd project
# 6. 拉取/推送代码
mg pull
mg push项目结构
mg-git-cli/
├── bin/
│ └── mg.js # CLI 入口
├── lib/
│ ├── commands/
│ │ ├── pull-push.js # pull/push 命令
│ │ ├── clone.js # clone 命令
│ │ ├── cd.js # cd 命令
│ │ ├── status.js # status 命令
│ │ └── config.js # config 命令
│ ├── config.js # 配置管理
│ ├── git-executor.js # Git 执行器
│ └── index.js
├── package.json
└── README.mdLicense
MIT
