【问题标题】:Push local master commits to remote branch将本地主提交推送到远程分支
【发布时间】:2011-03-13 11:24:42
【问题描述】:

我一直在处理远程 git 存储库的本地克隆,将我的更改提交到我的本地主分支。现在,我想将我的提交推送到远程存储库。但是,我想让我的本地提交与远程主分支分开,这样我就不会破坏任何东西。如何将本地提交推送到新的远程分支?

【问题讨论】:

  • 为什么不合并到本地跟踪分支,然后将本地分支推送到远程分支?

标签: git


【解决方案1】:

您应该运行git help push,它会告诉您推送到的 refspec 的语法。总之,git push <remotename> <local_branch_name>:<remote_branch_name>

【讨论】:

  • 对我来说,我必须做git remote(获取远程名称,我的来源)git push -f origin UI-Addition:UI-Addition 没有-f 选项,它将不允许操作。
  • 这对我来说失败了。它说error: unable to push to unqualified destination: temp2 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.
【解决方案2】:

我无法用一个命令来做到这一点。首先,我将所有更改提交给我的本地主人。然后我使用

创建一个名为“mybranch”的新本地分支
git checkout -b mybranch

然后我使用

git push -u origin mybranch

在我的情况下,origin 是远程名称。您的远程名称可能不同。您可以使用git remote -v 来查看您的远程名称应该是什么。

推送后,如果你愿意,你可以使用这两个命令摆脱你的本地分支

git checkout master
git branch -d mybranch

希望有帮助。

【讨论】:

    【解决方案3】:

    我所做的是创建一个新的本地分支,例如将其命名为 test1

    > git checkout -b test1

    此命令将创建一个分支并直接切换到它,然后通过键入

    将新的本地分支推送到 GitHub 或 GitLab 的远程存储库

    > git push origin test1

    不要忘记通过键入来检查正确的链接。

    > git remote --v

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 1970-01-01
      • 2016-10-25
      • 2013-08-31
      • 2017-03-08
      • 2013-08-01
      • 2020-02-05
      • 2015-08-16
      • 2013-04-10
      相关资源
      最近更新 更多