Git 安装与配置
Git 支持多平台安装,安装后即可快速上手使用。
Windows 安装
方法一:官网下载
- 访问 https://git-scm.com/download/win
- 下载安装包
- 运行安装程序,按向导完成安装
方法二:包管理器
Bash
# 使用 winget
winget install Git.Git
# 使用 Chocolatey
choco install git
# 使用 Scoop
scoop install git
macOS 安装
Bash
# 使用 Homebrew
brew install git
# 使用 Xcode Command Line Tools
xcode-select --install
Linux 安装
Bash
# Debian/Ubuntu
sudo apt update && sudo apt install git
# CentOS/RHEL
sudo yum install git
# Fedora
sudo dnf install git
# Arch Linux
sudo pacman -S git
验证安装
Bash
# 查看 Git 版本
git --version
# 输出示例
# git version 2.43.0
查看配置信息
Bash
# 查看所有配置
git config --list
# 查看系统级配置
git config --system --list
# 查看全局级配置
git config --global --list
# 查看仓库级配置
git config --local --list
安装完成后,需先配置用户信息才能正常提交代码。
配置优先级
| 级别 | 作用范围 | 配置文件位置 |
|---|---|---|
| --system | 所有用户 | /etc/gitconfig |
| --global | 当前用户 | ~/.gitconfig |
| --local | 当前仓库 | .git/config |
优先级从高到低:local > global > system
要点总结
- Windows 可通过官网下载或包管理器安装
- macOS 推荐使用 Homebrew 安装
- Linux 使用各发行版包管理器安装
- 安装后用
git --version验证 - 配置优先级:local > global > system
📝 发现内容有误?点击此处直接编辑