git 将远程分支合并到另一个本地分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45737121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge a remote branch into another local branch
提问by user1012181
This might be a duplicate question, but I couldn't figure out how can I go about it. I'm trying to merge a remote branch say remoteBranch
which is not a master branch to my local branch localBranch
.
这可能是一个重复的问题,但我不知道我该如何解决。我正在尝试合并一个远程分支,说它remoteBranch
不是我本地分支的主分支localBranch
。
One of my developer added a new branch for an api end point on remote branch remoteBranch
. As a frontend developer, I need to fetch that branch and merge it with my local development branch localBranch
to make use of that api end point. How can I do this?
我的一位开发人员为远程分支上的 api 端点添加了一个新分支remoteBranch
。作为前端开发人员,我需要获取该分支并将其与我的本地开发分支合并localBranch
以利用该 api 端点。我怎样才能做到这一点?
回答by hspandher
Simply merge it.
简单地合并它。
git fetch
git checkout localBranch
git merge remoteBranch
回答by Nitram
According to the documentation of git-merge
you can merge any other branch with your local branch.
根据git-merge
您可以将任何其他分支与本地分支合并的文档。
Your current branch has to be your localBranch
. To merge the remote branch simply type:
您当前的分支必须是您的localBranch
. 要合并远程分支,只需键入:
git merge remoteName/remoteBranch
In this case I assumed the name of your remote that contains the branch you need to be called remoteName
. It may be called differently like origin
or upstream
. You need to make sure that your local reference to the remove branch is up to date. So perform a fetch
command before doing the merge like so:
在这种情况下,我假设您的遥控器的名称包含您需要调用的分支remoteName
。它的名称可能不同,例如origin
或upstream
。您需要确保您对 remove 分支的本地引用是最新的。因此fetch
,在进行合并之前执行命令,如下所示:
git fetch remoteName
Does this help you?
这对你有帮助吗?
回答by Sam
To merge remoteBranch into localBranch
将 remoteBranch 合并到 localBranch
git fetch
git merge localBranch remoteName/remoteBranch
where remoteName is probably "origin", you can find that by git remote -v
其中 remoteName 可能是“起源”,您可以通过 git remote -v
However, sometimes you may want to rebase (re-writing history to keep sequence of commits "clean") instead of merge (which also adds a merge commit)
但是,有时您可能想要 rebase(重写历史记录以保持提交序列“干净”)而不是合并(这也会添加合并提交)
You can rebase a remoteBranch into a localBranch using:
您可以使用以下命令将 remoteBranch 变基为 localBranch:
git fetch
git checkout localBranch
git rebase remoteName/remoteBranch
ref: https://www.atlassian.com/git/tutorials/merging-vs-rebasing
参考:https: //www.atlassian.com/git/tutorials/merging-vs-rebasing