Skip to main content

新增 & 编辑 git 配置

git 的配置有3个类型,分别是 local(当前仓库,.git/config)、global(当前用户,~/.gitconfig)、system(系统,/etc/gitconfig),优先级从高到低。 local 为默认类型。

写入配置

git config --system name value
git config --global name value
git config name value

删除配置

git config --unset --system name
git config --unset --global name
git config --unset name

编辑配置(打开编辑器)

git config --edit --system
git config --edit --global
git config --edit

配置文件示例

[user]
name = TSY
[init]
defaultBranch = master
[alias]
ad = add .
cm = commit -m
acm = !git add . && git commit -m
ac = !git add . && git commit
lg = log --decorate=full --color=always --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cblue %H%d - %ad - %an(%ae) - %s'
ri = rebase --ignore-date -i
rh = reset --hard HEAD
ra = commit --amend --reset-author
cp = cherry-pick
mf = merge --ff
mn = merge --no-ff
mfs = merge --ff --squash
mns = merge --no-ff --squash
co = checkout
cb = checkout -b
pr = pull -r
sl = stash list
sp = stash pop
df = diff