blog
blog copied to clipboard
Git_2 Git 配置(git config)
获取帮助
若你使用 Git 时需要获取帮助,有三种方法可以找到 Git 命令的使用手册:
-
git help <verb>
-
git <verb> --help
-
man git-<verb>
例如,要想获得 config 命令的手册,执行 git help config
初次运行 Git 前的配置
Git 自带一个
git config
的工具来帮助设置控制 Git 外观和行为的配置变量。
配置用户信息
当安装完 Git 应该做的第一件事就是设置你的用户名称与邮件地址。 这样做很重要,因为每一个 Git 的提交都会使用这些信息,并且它会写入到你的每一次提交中,不可更改:
-
git config --global user.name "userName"
-
git config --global user.email [email protected]
再次强调,如果使用了 --global
选项,那么该命令只需要运行一次,因为之后无论你在该系统上做任何事情, Git 都会使用那些信息。 当你想针对特定项目使用不同的用户名称与邮件地址时,可以在那个项目目录下运行没有 --global
选项的命令来配置。
检查配置信息
-
使用
git config --list
命令来列出所有 Git 当时能找到的配置。$ git config --list credential.helper=osxkeychain user.name=李庆权 [email protected]
-
使用
git config <key>
来检查 Git 的某一项配置$ git config user.name 李庆权
注意
只要配置了 user.email=GitHub注册邮箱,提交代码到 Github 时就会显示提交者是当前 GitHub 用户。
$ vim ~/.gitconfig
# or: $ git config --global --edit
# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
# name = Qingquan Li # default use system username on macOS
email = [email protected] # GitHub Email