1 Git安装
1.1 安装地址
-
Git 官网:https://git-scm.com
-
Git 官方文档地址:https://git-scm.com/book/zh/v2
-
macOS 平台 Git 下载地址:https://git-scm.com/download/mac
-
Windows 平台 Git 下载地址:https://git-scm.com/download/win
-
Linux 平台 Git 下载地址:https://git-scm.com/download/linux
1.2 验证
windows版本的安装完成之后,会出现三个图标,大家可以根据操作习惯自行选择:
- Git Bash:Unix与Linux风格的命令行,使用最多,推荐最多
- Git CMD:Windows风格的命令行
- Git GUI:图形界面的Git,不建议初学者使用,尽量先熟悉常用命令
安装完成后,可通过查看git版本号验证是否安装成功,命令为:
$ git --version
比如,我的版本为2.33.0.windows.2:
2 配置
Git提供“git config”命令,专门用来操作配置相关内容。
2.1 config 的三个作用域
命令 | 作用域范围 | 使用频率 | 配置文件所在地 |
---|---|---|---|
git config --local | local 只对当前仓库有效 | .git/config | |
git config --global | global 对登录⽤户所有仓库有效 | 工作当中最常用 | 个人home目录下的.gitconfig |
git config --system | system对系统的所有⽤户有效 | 基本不用 | git安装目录 |
注意:缺省等同于 local
2.2 查看config配置
$ git config --list
$ git config --list --local
$ git config --list --global
$ git config --list --system
2.3 配置用户信息
配置用户信息,以local为例:
$ git config --local user.name "your_name"
$ git config --local user.email "your_email@xxx.com"
清除用户信息,以local为例:
$ git config --local --unset user.name
$ git config --local --unset user.email
2.4 操作示例
查看local配置,如下,没有配置用户名和邮箱:
配置用户名及邮箱:
查看当前配置信息,用户名邮箱已经设置成功:
清除用户名及邮箱:
查看当前配置信息,如下,用户名及邮箱已被清除: