git config

Git中有三层config文件:系统、全局、本地

查看不同级别的配置文件:

#查看系统 config
git config --system --list
  
#查看当前用户(global)配置
git config --global  --list

#查看当前仓库配置信息
git config --local  --list
  1. /etc/gitconfig:包含了适用于系统所有用户和所有项目的值。注是git的安装目录(Win:D:\Git\mingw64\etc\gitconfig) --system 系统级

  2. ~/.gitconfig:只适用于当前登录用户(全局)的配置。(Win:C:\Users\Administrator.gitconfig) --global 全局

  3. 位于git项目目录中的.git/config:适用于特定git项目(本地)的配置。--local当前项目

对于同一配置项,三个配置文件的优先级是 系统 < 全局 < 本地

设置用户名与邮箱(用户标识,必要)

  1. 当你安装Git后首先要做的事情是设置你的用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:
git config --global user.name "***"          #名称
git config --global user.email ****@qq.com   #邮箱

添加或删除配置项

git config [--local|--global|--system]  section.key value

[--local|--global|--system]  #可选的,对应本地,全局,系统不同级别的设置
section.key #区域下的键
value #对应的值
--local 项目级
--global 当前用户级
--system 系统级 

删除配置项

git config [--local|--global|--system] --unset section.key

更多配置项

git config --global color.ui true   #打开所有的默认终端着色
git config --global alias.ci commit   #别名 ci 是commit的别名
[alias]  
co = checkout  
ci = commit  
st = status  
pl = pull  
ps = push  
dt = difftool  
l = log --stat  
cp = cherry-pick  
ca = commit -a  
b = branch 

user.name  #用户名
user.email  #邮箱
core.editor  #文本编辑器  
merge.tool  #差异分析工具  
core.paper "less -N"  #配置显示方式  
color.diff true  #diff颜色配置  
alias.co checkout  #设置别名
git config user.name  #获得用户名
git config core.filemode false  #忽略修改权限的文件  

解决git每次提交和拉取代码需要输入用户名和密码问题

# 
git config --global credential.helper store

# 再输入一次正确的用户名和密码,就可以了