【问题标题】:How in GitLab push changes to a remote branch that has diverged from non-master branch?GitLab 如何将更改推送到与非主分支不同的远程分支?
【发布时间】:2020-12-01 06:04:22
【问题描述】:

我的分支dev_match_test 是分支origin/dev 的更新。

我想将 dev_match_test 分支的本地更改发送到远程存储库,

这样将dev_match_test 合并到dev 的合并请求可以在以后获得批准。

git status 命令告诉我们:

On branch dev_match_test
Your branch is ahead of 'origin/dev' by 22 commits.
    (use "git push" to publish your local commits)

git push 返回错误:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:dev

To push to the branch of the same name on the remote, use

    git push origin dev_match_test

尝试两个建议的选项都没有好处:

git push origin HEAD:dev

返回错误

remote: GitLab: You are not allowed to push code to protected branches on this project.

我怀疑这是因为我试图将更改推送到dev,但我没有这样做的权限。相反,我想推送到dev_match_test

git push origin dev_match_test

只返回一条消息Everything up-to-date,什么都不做。

问题:如何将本地更改推送到dev_match_test 分支?

【问题讨论】:

    标签: git github gitlab branch


    【解决方案1】:

    最简单的方法可能是简单地从您所在的当前分支创建一个新分支,推送到远程,然后将新分支合并到 dev 中。

    1. 从当前分支创建一个新分支:

    git checkout -b newBranchName

    1. 推送到远程:

    git push -u origin newBranchName

    1. 在 GitLab 中,为 newBranchName 创建一个合并请求到 dev 中

    请注意,这并不能解决您的分支 dev_match_test 未正确推送到远程的问题。为了解决这个问题,更多信息会有所帮助。我怀疑分支 dev_match_test 设置为从 origin/dev 而不是 origin/dev_match_test 跟踪。如果您可以发送 git remote -v 的输出(请隐藏 URL),这可能会有所帮助。

    【讨论】:

      【解决方案2】:

      如果您收到“一切都是最新的”消息,这意味着您过去的所有本地提交都已推送到远程。

      只需在 GitLab 中创建一个新的合并请求并选择正确的目标 (dev) 和源 (dev_match_test) 分支,您就应该准备就绪。

      【讨论】:

        猜你喜欢
        • 2011-06-09
        • 2020-05-22
        • 2018-09-07
        • 1970-01-01
        • 1970-01-01
        • 2021-11-21
        • 2015-04-02
        • 2018-10-02
        • 2020-07-13
        相关资源
        最近更新 更多