Git 合并远程分支?

Git 分布式支持的很好,我们可以同时和多个远程库保持联系;既然同时和多库保持联系,那么你就要对多个远程库的同步保持一个敏锐的意识。
虽然看起来很简单的一句话,但对于已经习惯了 svn 这种中心控制型代码管理模式的程序员来说,是有些挑战的;对多线联系感觉困扰的情况,估计和缺乏自治传统的文化或许也有些关系;

应用场景
Git 合并远程分支?_第1张图片
soho作为一个控制中心,在3和236之间做同步
  • A 可能会提交;
  • B 可能会提交;
  • soho 通常会提交;
有了分叉(diverged)
Git 合并远程分支?_第2张图片
origin 和 prod 分叉了
  • 产生分叉的机理不明(或许和 rebase 有关?);
  • 希望 origin 和 prod 保持一致;
合并远程分支
Git 合并远程分支?_第3张图片
git 合并
  • 合并 prod/master
    origin 是通常的源码库,希望将 prod 上的修改合并过来;
  • 做法
git pull prod master
git pull
git merge prod/master
git push
git push prod master:master

或许可以简单地说,将 prod 和 origin 两者上的变化加载到 soho 本地融合起来,然后再分别推送到远程;

  • 本地分支最好及时关联远程分支,即:使用 -u 或 --set-upstream 或 --set-upstream-to 选项;
    Why do I need to do --set-upstream all the time?

You can also explicitly tell git pull what remote branch to pull (as it mentions in the error message):
git pull , or git pull
Be careful with this, however: if you are on a different branch and do an explicit pull, the refspec you pull will be merged into the branch you're on!
当你这样做的时候,请务必有意识地了解明白这样做带来的后果;

  • Git の 运行配置(git config)
参考
  • Git: Merge a Remote branch locally
  • How to merge remote master to local branch

你可能感兴趣的:(Git 合并远程分支?)