7小时学会Git教程 (4)

84 阅读1分钟

远程仓库

4.1 远程仓库基础

  • git remote: 管理远程仓库。

  • git remote add <name> <URL>: 添加一个远程仓库。

  • git remote -v: 显示远程仓库列表及其URL。

  • git remote show <name>: 显示特定远程仓库的详细信息。

4.2 克隆远程仓库

  • git clone: 克隆远程仓库到本地。

  • git clone <URL>: 从远程仓库克隆到本地。

  • git clone -b <branch> <URL>: 克隆特定分支。

4.3 推送与拉取

  • git push: 将本地更改推送到远程仓库。

  • git push <remote> <branch>: 推送本地分支到远程仓库。

  • git pull: 从远程仓库拉取更改并合并到本地仓库。

  • git pull <remote> <branch>: 拉取远程分支并合并到当前分支。

4.4 多个远程仓库

  • git remote: 多个远程仓库的管理。

  • git remote add <name> <URL>: 添加额外的远程仓库。

  • git remote set-url <name> <newURL>: 修改远程仓库的URL。

  • git remote remove <name>: 移除远程仓库。

4.5 远程分支

  • git branch -r: 查看远程分支。

  • git checkout -b <local_branch> <remote_branch>: 创建并切换到远程分支的本地副本。

4.6 授权和认证

  • SSH Keys: 配置SSH密钥,确保远程操作的安全性。

  • HTTP认证: 在使用HTTP协议时,处理认证相关问题。

4.7 协同工作

  • Forking: 在开源项目中使用分叉(Fork)来贡献更改。

  • Pull Requests: 提交更改并请求合并到原始项目。

4.8 冲突解决

  • 解决冲突: 当合并出现冲突时的解决方法。

  • git pull --rebase: 使用rebase方式避免合并冲突。