将一个新的上游分支推送到远程仓库

3

几周前,我fork了一个项目。主要的存储库在私人服务器上。

$ # 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 '...'

我该如何在远程仓库上创建这个分支并将其推送到其中?
2个回答

1

尝试:

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

如果那不起作用,请尝试:
$ git checkout BRANCH_A; git push origin BRANCH_A

谢谢,第一行就可以了。 - user699082

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接