本文介绍了我可以为一个本地分支定义多个上游分支吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在git中有一个分支,其中有2个上游分支,这样它就从两个分支中拉出并推到其中一个...

I'm looking to have a branch in git that has 2 upstream branches, such that it pulls from both of them and pushes to one of them...

这是场景:

MY_BRANCH --> ORIGINAL_BRANCH
MY_BRANCH --> MY_BRANCH

因此,我的新分支MY_BRANCHORIGINAL_BRANCHMY_BRANCH(在origin处)提取,并推送到MY_BRANCH(在origin处).

So, my new branch, MY_BRANCH, pulls from both ORIGINAL_BRANCH and MY_BRANCH (at the origin), and pushes to MY_BRANCH (at the origin).

在git中可以吗?
我添加了ORIGINAL_BRANCH作为上游,因此当我进入git pull时,它会从上游拉出.当我执行git push时,它会推到MY_BRANCH,这很好.
但是,如何使它也跟随MY_BRANCH并从中退出呢?
(原因是其他开发人员可能在其中添加了某些内容,而不是ORIGINAL_BRANCH).

Is this possible in git?
I've added ORIGINAL_BRANCH as the upstream, so when I go git pull it pulls from it. And when I do git push it pushes to MY_BRANCH, which is good.
But how do I get it to follow MY_BRANCH as well, and pull from it too?
(reason for this is other developers might add something to it and not the ORIGINAL_BRANCH).

有什么想法吗?

推荐答案

如"",您不能为给定本地分支注册多个上游分支.

As mentioned in "How to track more than one remote with a given branch using Git?", you cannot register more than one upstream branch for a given local branch.

因此,您需要定义一个别名,该别名将两次调用git pull(对于第二次调用,是从原点开始的MY_BRANCH)

So you need to define an alias which will call git pull twice (with, for the second call, the MY_BRANCH from origin)

这篇关于我可以为一个本地分支定义多个上游分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!