Git安装
Git 安装
Git 是分布式版本控制系统,Hexo 需要使用 Git 来管理博客源码和部署。
为什么需要 Git
- 版本管理:追踪博客源码的每次修改
- 部署工具:Hexo 部署到 GitHub Pages 需要 Git
- 协作开发:多人协作或使用 GitHub Actions 自动部署
Windows 安装
- 访问 Git 官网
- 下载安装包并运行
- 安装时建议选择:
- 默认编辑器:选择你习惯的编辑器(如 VS Code)
- PATH 环境:选择 Git from the command line and also from 3rd-party software
- 其他选项保持默认即可
- 安装完成后打开命令提示符验证:
macOS 安装
在弹出的窗口中点击”安装”即可。
方法二:Homebrew
方法三:官网下载
访问 Git 官网 下载安装包。
Linux 安装
Ubuntu / Debian
1 2
| sudo apt update sudo apt install git
|
CentOS / RHEL
Arch Linux
基本配置
安装完成后,配置你的用户信息:
1 2
| git config --global user.name "你的名字" git config --global user.email "你的邮箱"
|
例如:
1 2
| git config --global user.name "Moriefy" git config --global user.email "moriefy@example.com"
|
验证配置:
1
| git config --global --list
|
配置 SSH 密钥(推荐)
使用 SSH 密钥可以免密码推送代码到 GitHub:
1 2 3 4 5 6 7 8
| ssh-keygen -t ed25519 -C "你的邮箱"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
|
添加公钥到 GitHub
- 复制公钥内容:
1
| cat ~/.ssh/id_ed25519.pub
|
- 登录 GitHub → Settings → SSH and GPG keys → New SSH key
- 粘贴公钥内容并保存
- 测试连接:
💡 提示:如果使用 HTTPS 方式推送代码,每次需要输入用户名和密码。配置 SSH 密钥后可以免密操作,推荐配置。