且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-08 09:55:29


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

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推到新的(组织)存储库中即可。

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.

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

现在,您应该在新存储库中拥有新的分支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.

第二种方法ID来更新当前存储库远程以指向新位置。

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

git remote set-url origin <new url>

然后推动分支。

上面两个都将具有相同的结果。区别在于,在第一个中,您添加了新遥控器,而在第二个中,您更改了遥控器。

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.