1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| 远程协作的整体步骤总结 1. git clone XXXX #克隆仓库 2. git branch -a #查看远程分支
#假设有以下这些分支 * master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/team #若只有master分支, 可以在本地创建新的分支, 然后切换到分支工作后, 直接进行commit, 然后git push origin remotebranchname, 这句话会再远程创建一个分支名为remotebranchname
3. git checkout -b team origin/team #创建本地分支和要跟踪的远程推送分支 4. git commit -m "add something" #首先对分支内容进行一些修改在team分支修改并提交 5. git push origin team #推送到远程分支team
#以下为推送成功信息 Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 275 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To git@github.com:Andrew-liu/CradleStudio.git a1de49f..3b6e09b team -> team #以下是协作冲突的处理, 此处code是远程仓库的代号, 可以通过git remote -v查看, code相当于默认的origin,即要推送或拉取的仓库 6. git push code team
#此时另一个协作着对同一个远程分支进行推送会发生错误 To git@github.com:Andrew-liu/CradleStudio.git ! [rejected] team -> team (fetch first) error: failed to push some refs to 'git@github.com:Andrew-liu/CradleStudio.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
7. git pull code team #首先应尝试pull解决冲突 From github.com:Andrew-liu/CradleStudio * branch team -> FETCH_HEAD a1de49f..3b6e09b team -> code/team Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the resul
8. 手动合并冲突, 查看冲突的文件, 会有明确的冲突信息标注 9. 重新推送成功 3b6e09b..7bc0cfa team -> team #修改推送成功, 完成一次远程协作
|