配置文件
配置文件权重 仓库>全局>系统
系统目录 /etc/gitconfig
用户目录 ~/.gitconfig
仓库目录 .git/config
(Git目录)
git config 查看配置文件
git config [--local][--global][--system] -l
$git config --local -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=git@gitServer:devops/cmdb-api.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.du.remote=origin
branch.du.merge=refs/heads/du
branch.master.remote=origin
branch.master.merge=refs/heads/master
(cmdb-api) jinfu->:~/yunwei/cmdbapi$
(cmdb-api) jinfu->:~/yunwei/cmdbapi$
(cmdb-api) jinfu->:~/yunwei/cmdbapi$
(cmdb-api) jinfu->:~/yunwei/cmdbapi$git config --global -l
core.excludesfile=/Users/jinfu/.gitignore_global
difftool.sourcetree.cmd=/usr/local/bin/bcomp "$LOCAL" "$REMOTE"
difftool.sourcetree.path=-ro
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
user.name=yin
user.email=yjd@zhuming.com
commit.template=/Users/jinfu/.stCommitMsg
(cmdb-api) jinfu->:~/yunwei/cmdbapi$git config --system -l
credential.helper=osxkeychain
git config 编辑配置文件
执行该命令会用配置文件中设定的编辑器打开配置文件
git config -e
默认编辑仓库级的配置文件
git config [–local|–global|–system] -e
# 设置全局的用户名和密码
git config --global user.name "yin"
git config --global user.email "yjd@zhuming.com"
增加配置项
git config [–local|–global|–system] –add section.key value
git config --global --add user.name "du"
会在~/.gitconfig 的 user下增加name=du(在name已经存在的情况下也会再添加name)
$git config --global -l
core.excludesfile=/Users/jinfu/.gitignore_global
difftool.sourcetree.cmd=/usr/local/bin/bcomp "$LOCAL" "$REMOTE"
difftool.sourcetree.path=-ro
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
user.name=yin
user.email=yjd@zhuming.com
user.name=du
commit.template=/Users/jinfu/.stCommitMsg
获取配置项
git config [–local|–global|–system] --get section.key
$git config --global --get user.name
yin