3

几周前我分叉了一个项目。主存储库位于私有服务器上。

$ # on gitserver.com
$ git clone --bare main.com:myproject

现在我添加了上游仓库并获取了新数据。

$ # on desktop.com
$ git clone gitserver.com:myproject
$ git remote add upstream main.com:myproject
$ git fetch upstream

当我尝试将上游分支推送到我自己的远程仓库时,对于存在于上游但不在源中的分支出现错误。

$ git push origin refs/remotes/upstream/BRANCH_A:BRANCH_A
Everything up-to-date
$ git push origin refs/remotes/upstream/BRANCH_B:BRANCH_B
error: unable to push to unqualified destination: BRANCH_B
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to '...'

如何在 origin 上创建这个远程分支并推送到它?

4

2 回答 2

1

尝试:

$ git push origin refs/remotes/upstream/BRANCH_A:refs/heads/BRANCH_A

如果这不起作用,请尝试:

$ git checkout BRANCH_A; git push origin BRANCH_A
于 2012-07-05T11:42:36.033 回答
1

这是我用来将所有分支从上游复制到原点(bash)的方法:

 for i in .git/refs/remotes/upstream/*; 
 do 
   z=${i#.git/refs/remotes/upstream/}; 
   git push origin refs/remotes/upstream/$z:refs/heads/$z;  
 done

复制所有标签更容易,因为“git fetch upstream”会给我本地的所有标签:

git push --tags origin

添加了这个,因为它也是我想做的一部分。

于 2013-10-01T15:22:57.653 回答