git-alias-1.0.0 is not a library.
Git-Short
一个快速的 Git 别名工具,支持两种调用方式。
特性
- 双模式调用: 支持直接调用 (
gs) 和 g 前缀调用 (g s)
- 115+ 内置别名: 覆盖所有常用 git 操作
- 自定义别名: 通过
~/.git-alias.toml 添加自定义别名
- Shell 补全: 支持 bash、zsh、fish 补全脚本
- 高性能: Rust 编译,启动时间 < 1ms
安装
从源码安装
git clone https://gitee.com/hnchencan/git-alias.git
cd git-alias
cargo build --release
./target/release/git-alias.exe install
快速安装 (推荐)
cargo build --release
./target/release/git-alias.exe install
这会将所有命令安装到 ~/.local/bin/。
配置
添加到 PATH
将以下内容添加到 .bashrc 或 .zshrc:
export PATH="$HOME/.local/bin:$PATH"
使用方法
基本命令
gs gba gcm "msg"
g s g ls g ba g cm "msg"
子命令
g list g list push g completions bash g init g install g --help
别名列表
运行 g list 查看所有别名。
Add (添加)
| 别名 |
命令 |
a / ga |
git add |
aa / gaa |
git add . |
Status (状态)
| 别名 |
命令 |
s / gs |
git status |
ss / gss |
git status -s |
sb / gsb |
git status -s -b |
Commit (提交)
| 别名 |
命令 |
cm / gcm |
git commit -m |
ca / gca |
git commit --amend |
cn / gcn |
git commit --no-edit --amend |
Push (推送)
| 别名 |
命令 |
p / gp / ps / gps |
git push |
pf / gpf |
git push --force-with-lease |
pu / gpu |
git push -u origin HEAD |
Pull (拉取)
| 别名 |
命令 |
pl / gpl |
git pull |
plr / gplr |
git pull --rebase |
Branch (分支)
| 别名 |
命令 |
b / gb |
git branch |
ba / gba |
git branch --all |
bra / gbra |
git branch -avv |
bd / gbH |
git branch --delete |
gbD |
git branch --delete --force |
Checkout (检出)
| 别名 |
命令 |
co / gco / c / gc |
git checkout |
cb / gcb |
git checkout -b |
Switch (切换)
| 别名 |
命令 |
sw / gsw |
git switch |
swc / gswc |
git switch --create |
swd / gswd |
git switch --detach |
swf / gswf |
git switch --force |
Log (日志)
| 别名 |
命令 |
l / gl |
git log (自定义格式) |
lg |
git log --oneline |
lgg |
git log --graph --oneline --all |
ls |
git log --no-merges |
lsa |
git log --no-merges --all |
lsm |
git log --all |
lss |
git log --no-merges --stat=200 |
Diff (差异)
| 别名 |
命令 |
d / gd / di / gdi |
git diff |
dc / gdc |
git diff --cached |
ds / gds |
git diff --staged |
dw / gdw |
git diff --word-diff |
Reset/Restore (重置/恢复)
| 别名 |
命令 |
rh / grh |
git reset --hard |
rs / grs |
git restore |
rsc / grsc |
git restore --staged |
Revert (回退)
| 别名 |
命令 |
rvr / grvr |
git revert |
Stash (储藏)
| 别名 |
命令 |
sh / gsh |
git stash |
shp / gshp |
git stash pop |
sha / gsha |
git stash apply |
shl / gshl |
git stash list |
shd / gshd |
git stash drop |
Remote (远程)
| 别名 |
命令 |
r / gr |
git remote |
rv / grv |
git remote -v |
ra / gra |
git remote add |
rrm / grrm |
git remote remove |
Fetch (获取)
| 别名 |
命令 |
f / gf |
git fetch |
fa / gfa |
git fetch --all --prune |
Merge (合并)
Rebase (变基)
| 别名 |
命令 |
rb / grb |
git rebase |
rbi / grbi |
git rebase -i |
Clone (克隆)
Tag (标签)
| 别名 |
命令 |
t / gt |
git tag |
tl / gtl |
git tag -l |
Blame (追溯)
Clean (清理)
| 别名 |
命令 |
clean |
git clean --interactive -d |
配置文件
创建配置文件 ~/.git-alias.toml:
g init
配置示例
[aliases]
my = ["status", "-s", "-b"]
pushf = ["push", "--force-with-lease"]
wip = ["add", "-A"]
[settings]
main_branch = "main"
verbose = false
Shell 补全
Bash
source <(g completions bash)
添加到 .bashrc 以持久化:
source <(g completions bash)
Zsh
source <(g completions zsh)
添加到 .zshrc 以持久化:
source <(g completions zsh)
Fish
g completions fish > ~/.config/fish/completions/g.fish
性能
- 二进制大小: ~1.1MB (release 编译)
- 启动时间: < 1ms (CPU 时间)
- 内存占用: < 3MB
许可证
MIT