git 在git中合并两个远程分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24147169/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:11:01  来源:igfitidea点击:

Merge two remote branches in git

gitgithubmerge

提问by spartak

EDIT

编辑

Let me paraphrase, I would like to merge two git repositories with the same name, but different remote.

让我解释一下,我想合并两个名称相同但远程不同的 git 存储库。

That is, I have a repo_name hosted in git, under a branch name of repo_name_a and I added another branch to git under branch name : repo_name_b

也就是说,我在 git 中托管了一个 repo_name,在 repo_name_a 的分支名称下,我在分支名称下向 git 添加了另一个分支:repo_name_b

Now, to merge those, what can I do ?

现在,要合并这些,我该怎么办?

回答by akgill

The answer I've given below was to the previous version of the asker's question. Now it seems to be a completely different question. This may not be relevant.

我在下面给出的答案是针对提问者问题的先前版本。现在这似乎是一个完全不同的问题。这可能不相关。

What you've described is basically how git is intended to be used, with additional features/work done in a branch, and then merged back to master when completed/reviewed.

您所描述的基本上是如何使用 git,在分支中完成附加功能/工作,然后在完成/后合并回 master。

git clone https://github.com/master_repo/master_repo

git clone https://github.com/master_repo/master_repo

is the correct command to get a copy of that repo into your local machine. To then make a branch to work off of,

是将该存储库的副本复制到本地计算机的正确命令。然后创建一个分支来工作,

git checkout -b test_repois also correct.

git checkout -b test_repo也是对的。

But then, when working in your new branch, you'll be doing git add <name of file>and git commitwhen working in that branch, many times, and then when you want to update the remote repository's history of your test branch, you'll do

但随后,在新的分支上工作时,你会做git add <name of file>,并git commit在该分支,工作时很多次,然后当你想更新你的测试分支的远程储存的历史,你会做

git push origin test_repo

git push origin test_repo

This means push my stuff to origin in the test_repo branch.

这意味着将我的东西推送到 test_repo 分支中的原点。

If you are working in a repo all by your lonesome, then you want to merge to master, on your local machine, the easiest thing to do is

如果你一个人在一个 repo 中工作,那么你想合并到 master,在你的本地机器上,最简单的方法是

git checkout master git merge test_repo

git checkout master git merge test_repo

You probably won't end up with merge conflicts, but if you do, you'll resolve them. And then from your local master branch, you can do

您可能不会以合并冲突告终,但如果这样做,您将解决它们。然后从你当地的主分支,你可以做

git push origin masterto update the remote branch.

git push origin master更新远程分支。

If you were working on a project with collaborators, instead you'd probably want to use the github website interface to create a "pull request" from the test_repo branch to the master branch. Your collaborators could then review your changes and suggest improvements and ultimately be in charge of merging your branch into master.

如果您正在与合作者一起处理项目,那么您可能希望使用 github 网站界面来创建从 test_repo 分支到主分支的“拉取请求”。然后,您的协作者可以查看您的更改并提出改进建议,并最终负责将您的分支合并到 master。

You can also do this if you're working on something yourself. Create a pull request with a high level description of what changes you are asking to have pulled back into master, and then you can merge the pull request into master on the web interface. This is a little bit of a safer, better method because it is eventually how you'll want to use git for collaboratively working on projects, and it leaves a nice descriptive history of what all the merges to master accomplished.

如果您自己在做某事,也可以这样做。创建一个拉取请求,其中包含您要求将哪些更改拉回 master 的高级描述,然后您可以在 Web 界面上将拉取请求合并到 master 中。这是一种更安全、更好的方法,因为它最终是您希望如何使用 git 协作处理项目的方式,并且它为所有要掌握的合并完成的内容留下了很好的描述性历史记录。

If you choose to do this, then once a branch is merged, you can delete it remotely and run git remote prune originlocally to delete your local branch (and all local branches that have been deleted remotely.)

如果您选择这样做,那么一旦分支合并,您可以远程删除它并在git remote prune origin本地运行 以删除您的本地分支(以及所有已远程删除的本地分支。)