简体   繁体   English

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

[英]How in GitLab push changes to a remote branch that has diverged from non-master branch?

My branch dev_match_test is an update to the branch origin/dev .我的分支dev_match_test是对分支origin/dev的更新。

I want to send my local changes of the dev_match_test branch to the remote repository,我想将dev_match_test分支的本地更改发送到远程存储库,

such that the merge request to merge dev_match_test into dev could be later approved.这样可以稍后批准将dev_match_test合并到dev的合并请求。

git status command tells that: 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)

but git push returns an error:但是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

Trying both suggested options gives no good:尝试两个建议的选项都没有好处:

git push origin HEAD:dev

returns an error返回错误

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

I suspect it's because I'm trying to push changes to dev and I don't have permission for that.我怀疑这是因为我试图将更改推送到dev而我没有权限。 Instead I want to push to dev_match_test .相反,我想推送到dev_match_test

git push origin dev_match_test

just returns a message Everything up-to-date and does nothing.只是返回一条消息Everything up-to-date ,什么都不做。

Question : how to push local changes to the dev_match_test branch?问题:如何将本地更改推送到dev_match_test分支?

What might be easiest is to simply make a new branch from the current branch you're on, push to remote, then merge the new branch into dev.可能最简单的方法是从您所在的当前分支创建一个新分支,推送到远程,然后将新分支合并到 dev 中。

  1. Make a new branch from current branch:从当前分支创建一个新分支:

git checkout -b newBranchName

  1. Push to remote:推送到远程:

git push -u origin newBranchName

  1. In GitLab, create a Merge Request for newBranchName into dev在 GitLab 中,为 newBranchName 创建一个 Merge Request 到 dev

Please note this does not fix your branch dev_match_test not properly pushing to remote.请注意,这不能修复您的分支 dev_match_test 未正确推送到远程。 To solve that, more information would be helpful.为了解决这个问题,更多信息会有所帮助。 I suspect that the branch dev_match_test is set up to track from origin/dev instead of origin/dev_match_test.我怀疑分支 dev_match_test 设置为从 origin/dev 而不是 origin/dev_match_test 跟踪。 If you could send the output of git remote -v (please hide URLs) that could be helpful.如果您可以发送 git 的git remote -v (请隐藏 URL),这可能会有所帮助。

If you get the message "everything up-to-date", that means that all your local commits have already been pushed to the remote in the past.如果您收到“一切都是最新的”消息,这意味着您的所有本地提交过去都已被推送到远程。

Simply create a new merge request in GitLab and select the proper target ( dev ) and source ( dev_match_test ) branch and you should be all set.只需在 GitLab 和 select 正确的目标 ( dev ) 和源 ( dev_match_test ) 分支中创建一个新的合并请求,您就应该准备就绪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM