将上游新分支推入原点

时间:2012-07-05 11:12:35

标签: git

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

$ # 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 个答案:

答案 0 :(得分:1)

尝试:

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

如果不起作用,请尝试:

$ git checkout BRANCH_A; git push origin BRANCH_A

答案 1 :(得分: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

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