Git基础配置(linux或windows cygwin)
设置名字和邮箱
- 设置名字
git config --global user.name "yourname"
- 设置邮箱
git config --global user.email "youremail"
配置文件存储
- /etc/gitconfig文件
通过--system属性访问,该文件含有对系统上所有用户都生效的配置文件。一般开启代码高亮功能可以配置在这里:git config --system color.ui true
- ~/.gitconfig文件
通过--global属性访问,该文件对当前用户有效。一般名字和邮箱就配置在这里:git config --global user.name "yourname" git config --global user.email "youremail"
-
.git/config文件
通过--local属性访问,该文件对当前库有效。一般用于设置一些当前库要使用的特殊配置。
如远程仓库地址等属性配置文件的优先级遵从于就近原则。
一些有用的配置
- core.editor
在windows cygwin环境下这个配置还是比较有用。cygwin默认安装的是旧版本的vim不太好用,我通常用我自己配置的emacs
这样每次我执行 git commit 时,我就不用再指定 -m "commit informaiton"了,这时git会打开我的emacs编辑器,我就可以再emacs里编辑我的提交信息了。git config --global core.editor emacs
- color.ui
设置color.ui为true来打开终端默认着色。设置完以后输入git命令会加上颜色,这很有用,特别是在使用git status命令的时候。
最后
关于git config命令,最详细的文档还是git config --help,它使用了Linux man命令格式,是使用git config的很好的参考文档。