git 如何将分支从一个 GitHub 存储库复制到另一个?

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

How to copy a branch from one GitHub repository to another?

gitgithubbranch

提问by Mason Wheeler

The Author had a respository, called Master.

作者有一个存储库,称为 Master。

I forked Master, and created branch A on it.
Then the Author created an Organization, forked Master to the Organization, and said that that should be the new official main repository.

我分叉了 Master,并在其上创建了分支 A。
然后作者创建了一个组织,将 Master 分叉到该组织,并说那应该是新的官方主存储库。

Then he invited me to join the Organization and now I have commit access.

然后他邀请我加入组织,现在我有提交访问权限。

I'd like to copy my branch A onto the Organization repository so that it will have branch A, (ie. not integrating the branch,) but looking around, I can't seem to find any simple way to do this.

我想将我的分支 A 复制到组织存储库中,以便它具有分支 A(即不集成分支),但环顾四周,我似乎找不到任何简单的方法来执行此操作。

Both my version and the Organization version were forked from Master, so it should be pretty straightforward to copy the branch over, but everything I can find when I search for instructions online seems to be all about copying branches to your local copy of the repository, which isn't what I'm trying to do.

我的版本和组织版本都是从 Master 分叉出来的,所以复制分支应该非常简单,但是我在网上搜索说明时能找到的一切似乎都是关于将分支复制到存储库的本地副本,这不是我想要做的。

Does anyone know how to do this?

有谁知道如何做到这一点?

回答by CodeWizard

I'd like to copy my branch A onto the Organization repository so that it will have branch A, (ie. not integrating the branch,) but looking around, I can't seem to find any simple way to do this.

我想将我的分支 A 复制到组织存储库中,以便它具有分支 A(即不集成分支),但环顾四周,我似乎找不到任何简单的方法来执行此操作。

Simply add the new remote (Organization) to your old repository (master).
Once you did it simply push the branch A to the new (organization) repository.

只需将新的远程(组织)添加到您的旧存储库(主)。
完成后,只需将分支 A 推送到新的(组织)存储库。

cd <old repository>
git remote add origin2 <new_url>
git push origin2 <branch A>

Now you should have the new branch A in your new repository.
The point is to add new remote and to push the branch to your new repository.

现在您应该在新存储库中拥有新分支 A。
关键是添加新的远程并将分支推送到您的新存储库。

Second way id to update the current repository remote to point to the new location:

更新当前存储库远程以指向新位置的第二种方式 id:

git remote set-url origin <new url>

And then push the branch.

然后推动分支。

Both of teh above will have the same result. The difference is that in the first one you add new remote while in the second one you change the remote.

以上两者都会有相同的结果。不同之处在于,在第一个中添加新遥控器,而在第二个中更改遥控器。

enter image description here

在此处输入图片说明