Git config

Git config详解

Git 配置有三个级别,按照优先级为:本地配置、全局配置和系统配置。本地配置的命令为:

git config --local

全局配置的命令为:

git config --global

系统配置的命令为:

git config --system

比如,我们要配置全局的用户名和密码,具体命令如下:

git config --global user.name haicoder git config --global user.email haicoder@haicoder.cn

Git config的增删改查

--add 表明可以有同样的多对键值对,具体命令如下:

# --add 表明可以有同样的多对键值对 git config --global --add user.name eoe

根据键查询值,命令如下:

git config user.name git config --get user.name

查询所有配置,具体命令如下:

git config --list --global

删除一个键只包含一个值:

git config --global --unset user.name

删除一个键中包含多个值:

git config --global --unset user.name eoe

修改某项配置:

git config --global user.name eoe

别名

在 Git 中, 我们可以给常用命令起别名,比如给 checkout 起别名为 co:

git config --global alias.co checkout

给 branch 起别名为 br:

git config --global alias.br branch

给 commit 起别名为 ci:

git config --global alias.ci commit

起别名之后,具体使用如下:

git co git ci