菜鸟笔记
提升您的技术认知

Git 的配置

 一般配置用户层面配置

Git 的配置从上到下分三层 system/global/local,使用三个不同参数进行设置,每个层次的配置存储在不同的位置,

1)./etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。(系统级别配置) system

2).~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使 Git 读或写这个特定的文件。(用户层面配置) global

3).位于 git 目录的 config 文件 (也就是 .git/config) :无论你当前在用的库是什么,特定指向该单一的库。每个级别重写前一个级别的值。因此,在.git/config 中的值覆盖了在/etc/gitconfig 中的同一个值。(仓库级别配置) local

 

通常我们只配置 global 级别

[root@ci-node1 ~]# git config --global user.name "Your Name"         // 配置用户,以便知道提交代码的人是谁
[root@ci-node1 ~]# git config --global user.email you@example.com    // 配置邮箱,以便联系到提交代码的人

配置完成以后global配置,在用户家目录下会创建  .gitconfig文件

我在root账户是在 /root/.gitconfig

查看文件内容

[root@ci-node1 ~]# cat .gitconfig 
[user]
    name = "name"
    email = "email"

查看配置文件

[root@ci-node1 ~]# git config --list
user.name="name"
user.email="email"

 

[root@ci-node1 ~]# git config
usage: git config [options]

Config file location
    --global              use global config file       // 全局配置
    --system              use system config file       // 系统配置
    --local               use repository config file   // 仓库配置