git-alias 1.0.1

A fast git alias tool with dual-style command support
git-alias-1.0.1 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"

使用方法

基本命令

# 直接调用 (必须以 g 开头)
gs          # git status
gba         # git branch --all
gcm "msg"   # git commit -m "msg"

# 通过 g 前缀调用
g s         # git status
g ls        # git log --no-merges
g ba        # git branch --all
g cm "msg"  # git commit -m "msg"

# 注意: g gps 这种用法不支持,gps 以 g 开头只能用直接调用

子命令

g list              # 列出所有别名
g list push         # 过滤显示 push 相关别名
g completions bash  # 生成 bash 补全脚本
g init              # 创建配置文件
g install           # 安装所有别名命令
g --help            # 显示帮助

别名列表

运行 g list 查看所有别名。

调用规则:

  • 直接调用(如 gs, gps, gba):必须以 g 开头
  • g 前缀调用(如 g s, g ps, g ba):别名不能以 g 开头
  • g 开头的别名不支持 g 前缀调用(如 g gps 报错)

Add (添加)

别名 命令
g a git add
ga git add
g aa git add .
gaa git add .

Status (状态)

别名 命令
g s git status
gs git status
g ss git status -s
gss git status -s
g sb git status -s -b
gsb git status -s -b

Commit (提交)

别名 命令
g cm git commit -m
gcm git commit -m
g ca git commit --amend
gca git commit --amend
g cn git commit --no-edit --amend
gcn git commit --no-edit --amend

Push (推送)

别名 命令
g ps git push
gps git push
g pf git push --force-with-lease
gpf git push --force-with-lease
g pu git push -u origin HEAD
gpu git push -u origin HEAD

Pull (拉取)

别名 命令
g p git pull
gp git pull
g pl git pull
gpl git pull
g plr git pull --rebase
gplr git pull --rebase

Branch (分支)

别名 命令
g b git branch
gb git branch
g ba git branch --all
gba git branch --all
g bra git branch -avv
gbra git branch -avv
g bd git branch --delete
gbD git branch --delete --force

Checkout (检出)

别名 命令
g co git checkout
gco git checkout
g c git checkout
gc git checkout
g cb git checkout -b
gcb git checkout -b

Switch (切换)

别名 命令
g sw git switch
gsw git switch
g swc git switch --create
gswc git switch --create
g swd git switch --detach
gswd git switch --detach
g swf git switch --force
gswf git switch --force

Log (日志)

别名 命令
g l git log (自定义格式)
gl git log (自定义格式)
g lg git log --oneline
g lgg git log --graph --oneline --all
g ls git log --no-merges
gls git log --no-merges
g lsa git log --no-merges --all
glsa git log --no-merges --all
g lsm git log --all
glsm git log --all
g lss git log --no-merges --stat=200
glss git log --no-merges --stat=200

Diff (差异)

别名 命令
g d git diff
gd git diff
g di git diff
gdi git diff
g dc git diff --cached
gdc git diff --cached
g ds git diff --staged
gds git diff --staged
g dw git diff --word-diff
gdw git diff --word-diff

Reset/Restore (重置/恢复)

别名 命令
g rh git reset --hard
grh git reset --hard
g rs git restore
grs git restore
g rsc git restore --staged
grsc git restore --staged

Revert (回退)

别名 命令
g rvr git revert
grvr git revert

Stash (储藏)

别名 命令
g sh git stash
gsh git stash
g shp git stash pop
gshp git stash pop
g sha git stash apply
gsha git stash apply
g shl git stash list
gshl git stash list
g shd git stash drop
gshd git stash drop

Remote (远程)

别名 命令
g r git remote
gr git remote
g rv git remote -v
grv git remote -v
g ra git remote add
gra git remote add
g rrm git remote remove
grrm git remote remove

Fetch (获取)

别名 命令
g f git fetch
gf git fetch
g fa git fetch --all --prune
gfa git fetch --all --prune

Merge (合并)

别名 命令
g mg git merge
gmg git merge

Rebase (变基)

别名 命令
g rb git rebase
grb git rebase
g rbi git rebase -i
grbi git rebase -i

Clone (克隆)

别名 命令
g cl git clone
gcl git clone

Tag (标签)

别名 命令
g t git tag
gt git tag
g tl git tag -l
gtl git tag -l

Blame (追溯)

别名 命令
g bl git blame
gbl git blame

Clean (清理)

别名 命令
g 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