一、 文件位置
Linux 系統
全局配置
~/.gitconfig
當前項目下
.git/.gitconfig(覆蓋用戶級)
二、配置簡介
這里有一些例子你可以試試:
$ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status
這意味着,當要輸入 git commit
時,只需要輸入 git ci
。 隨着你繼續不斷地使用 Git,可能也會經常使用其他命令,所以創建別名時不要猶豫。
在創建你認為應該存在的命令時這個技術會很有用。 例如,為了解決取消暫存文件的易用性問題,可以向 Git 中添加你自己的取消暫存別名:
$ git config --global alias.unstage 'reset HEAD --'
這會使下面的兩個命令等價:
$ git unstage fileA $ git reset HEAD -- fileA
三、系統配置
全局
$ git config --global user.name cpz $ git config --global user.email cpz@test.com
局部(當前項目)
$ git config user.name cpz $ git config user.email cpz@test.com
快速打開gitconfig
git config [--global] --edit
修改編輯器
$ git config --global core.editor emacs
查看gitconfig內容
$ git config --list
git alias配置
[alias] st = status -sb co = checkout br = branch mg = merge ci = commit ds = diff --staged dt = difftool mt = mergetool last = log -1 HEAD latest = for-each-ref --sort=-committerdate --format=\"%(committername)@%(refname:short) [%(committerdate:short)] %(contents)\" ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short type = cat-file -t dump = cat-file -p lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit [core] autocrlf = true [push] default = simple [color] ui = auto [color "branch"] current = yellow reverse local = yellow remote = green [color "status"] added = yellow changed = green untracked = cyan [color "diff"] meta = yellow frag = magenta bold commit = yellow bold old = red bold new = green bold whitespace = red reverse [color "diff-highlight"] oldNormal = red bold
可以參考:
https://github.com/SixArm/sixarm_git_gitconfig
https://github.com/GitAlias/gitalias