git
  • 安装教程
  • 本地仓库
    • 工作区与版本库
    • 版本管理
      • 创建版本库
      • 提交修改
      • 撤消修改
      • 删除文件
    • 分支管理
      • 创建分支
      • 合并分支
      • 删除分支
    • 标签管理
      • 创建标签
      • 删除标签
  • 远程仓库
    • 初始化远程库
    • 克隆远程库
    • 多人协作
    • 远程分支
    • 远程标签
    • 关于origin
    • 关于upstream
  • 关于config
    • 关于name与email
    • window上的凭证
  • git常用命令
  • github的使用
  • 容器跑gogs
  • 项目版本管理
    • GitFlow
Powered by GitBook
On this page

Was this helpful?

  1. 远程仓库

多人协作

Previous克隆远程库Next远程分支

Last updated 5 years ago

Was this helpful?

本节将介绍一个多人协作的例子。

假设 是一个远程空仓库。

1、A主机初始化远程仓库

首先,在A主机上新建一个learngit仓库,创建master分支与dev分支

$ mkdir learngit
$ cd learngit
$ vi readme.md
$ git init
$ git add *
$ git commit -m "initialization"
$ git branch dev

然后同步到远程的learngit仓库

$ git remote add origin http://x.x.x.x:xx/pshizh/learngit.git
$ git checkout master
$ git push -u origin master
$ git checkout dev
$ git push -u origin dev

2、B主机克隆远程仓库

在B主机上克隆远程仓库的master分支下来

$ git clone http://x.x.x.x:xx/pshizh/learngit.git

再拉取远程仓库的dev分支下来

$ cd learngit
$ git pull origin dev:dev

3、A主机修改master分支

A主机修改master分支下的readme.md文件,然后commit、pull并push

$ git checkout master
$ vi readme.md
$ git add readme.md
$ git commit -m "conficted line by A"
$ git pull
$ git push

说明,最后两行 git pull 与 git push 其实等价于 git pull origin master 与 git push origin master , 由于在步骤1中第一次push时的命令 git push -u origin master 添加了参数 -u ,相当于把本地的master分支与origin的master分支建立了连接,所以后面再pull与push的时候,就可以省略远程仓库的名字与分支了

4、B主机修改master分支

B主机修改master分支下的readme.md文件,然后commit、pull、处理冲突、push

$ git checkout master
$ vi readme.md
$ git add readme.md
$ git commit -m "conflicted line by B"
$ git pull
# 手动处理冲突
$ git add readme.md
$ git commit -m "conflicted line dealed with"
$ git push
http://x.x.x.x:xx/pshizh/learngit.git