叉公共仓库到私人和接受公共提交

问题描述:

让我们市民的github仓库(A)https://github.com/schacon/example叉公共仓库到私人和接受公共提交

我想这叉库来到位桶私人回购(B)。

我希望收到库公共提交到库B.

这可能吗?

  • 在BitBucket中创建一个名为B的新私人存储库。在本地克隆B
  • 转到存储库B。使用GitHub存储库(repo A)的URL添加一个新的远程(比如repoA)。

    $ git remote add repoA <A-repo-url> 
    $ git remote -v      # see the remotes 
    
  • 拉库的提交/变为库B.

    $ git pull repoA master    # B's master = A's origin/master 
    
  • 按下更改库B(到位桶)。

    $ git push origin HEAD    # B's origin/master = A's origin/master 
    

取库A.

$ git fetch repoA 

各分支机构与A分支的历史记录创建一个新的分支(比如,next

$ git checkout -b next repoA/next # create a local 'next' branch = repoA/next 

推送当地next分支更改为存储库B的next分支。

$ git push origin next 

在未来,保持同步与存储库A.

$ git fetch repoA 

现在拉A分支到B分支,或者只是结帐像上面的例子一个新的分支。然后推送到B的存储库。

注意repoA是您的存储库A的URL和origin是存储库B的URL在这里。

+0

感谢您快速回答!来自github的原始库(A)包含两个分支'master'和'next','next'是我最需要的分支。现在我做了你提到的所有事情,但是我没有在我的存储库中看到该分支。 – ememem

+0

以及我应该如何接收从存储库(A)到存储库(B)的新提交,以便它将保持同步?谢谢! – ememem

+0

'git fetch repoA --all'中的'--all'不会获取所有分支。 '--all'将从所有配置的远程回购站获取。 '--all'和一个repo参数将会出错。远程通常默认配置为获取所有分支,所以只需'git fetch repoA'即可获得所有分支。 –

有几个方法可以做到这一点:

  1. 只是严格镜像回购 - 没有试图发展工作的本地副本
  2. 不要在本地工作区的开发工作,而推/拉至2作为工作流程的一部分不同的遥控器。

对于镜像副本(例如所有的分支),其在这里的github文档覆盖相当清楚:https://help.github.com/articles/duplicating-a-repository/。但是,请注意,这些方法严格用于镜像回购,即他们创造了不适合做本地开发工作的本地回收。

简而言之:

A.对于一次性镜像副本:

$ git clone --bare https://github.com/exampleuser/A.git 
$ cd A.git 
$ git push --mirror https://github.com/exampleuser/B.git 
$ cd .. 
$ \rm -rf A.git 

B.对于正在进行的镜像副本:

设置 - 首先创建目标到位桶回购,然后本地

$ git clone --mirror https://github.com/exampleuser/A.git 
$ cd A.git 
$ git remote set-url --push origin https://bitbucket.com/exampleuser/B.git 

然后根据需要,从A更改并将它们推送到B

$ cd A.git 
$ git fetch -p origin 
$ git push --mirror