在GitLab中如何将更改推送到与非主分支不同的远程分支?

问题描述

我的分支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分支?

解决方法

最简单的方法是简单地从当前所在的分支创建一个新分支,推送到远程,然后将新分支合并到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)。

,

如果收到消息“一切都是最新的”,则表示您过去所有本地提交都已被推送到远程。

只需在GitLab中创建一个新的合并请求,然后选择适当的目标(dev)和源(dev_match_test)分支,就可以完成所有工作。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...