第六章:Git 远程仓库¶
远程操作¶
# 查看远程仓库
git remote -v
# 添加远程仓库
git remote add origin https://github.com/user/repo.git
# 推送到远程
git push origin main
# 拉取远程更新
git pull origin main
# 克隆仓库
git clone https://github.com/user/repo.git
SSH 配置¶
# 生成 SSH 密钥
ssh-keygen -t ed25519 -C "your_email@example.com"
# 查看公钥
cat ~/.ssh/id_ed25519.pub
# 测试连接
ssh -T git@github.com
# 使用 SSH 地址
git remote set-url origin git@github.com:user/repo.git
协作工作流¶
Fork 工作流¶
# 1. Fork 仓库到个人账号
# 2. 克隆 Fork 的仓库
git clone https://github.com/your-username/repo.git
# 3. 创建分支
git checkout -b feature/new-feature
# 4. 提交更改
git add .
git commit -m "Add new feature"
# 5. 推送到 Fork
git push origin feature/new-feature
# 6. 创建 Pull Request
小结¶
Git 远程仓库要点:
- 远程操作:push、pull、clone
- SSH 配置:密钥生成、连接测试
- 协作工作流:Fork、PR
下一章我们将学习 Git 高级用法。