更改本地关联的远程分支?
我正在 git 存储库中维护一个分支(图中的本地/远程)。我在分支的本地版本中处理的代码实际上属于另一个分支(图中的分支 2)。
不幸的是,虽然我没有推送分支的本地提交,但另一位开发人员推送了他们的版本,这在原始图中创建了情况。
为了尝试修复该问题,我将本地副本重新设置为分支 2。 但是,我的本地副本仍然与其原始远程分支相关联。
我想将其与分支 2 关联,然后推送,以获得所需图表中的结果。
我怎样才能实现这个目标?
I am maintaining a branch in a git repo (the local/remote in the diagram). The code I worked on in the local version of the branch actually belongs in the other branch (Branch 2 in the diagram).
Unfortunately, while I had not pushed my local commit of the branch, another developer pushed their version which created the situation in the original diagram.
In order to attempt to fix it, I rebased my local copy onto Branch 2.
However, my local copy is still associated with it's original remote branch.
I would like to associate it with Branch 2 and then push, to get the outcome in the desired diagram.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想将本地分支推送到具有不同名称的分支,你只需执行 git push remoterepo localbranch:remotebranch 即可。
如果需要更改上游,请使用 gitbranch --set-upstream-to=remotebranch localbranch 。
If you want to push a local branch to a branch with different name, you just do
git push remoterepo localbranch:remotebranch
.If you need to change the upstream, use
git branch --set-upstream-to=remotebranch localbranch
.由于这个问题被标记为“gitkraken”,因此您可以在 GitKraken 中执行此操作:
如果您只想将本地分支推送到不同的远程分支,只需将本地分支拖放到远程分支上并选择“将本地推送到源/远程”,
。 GitKraken 网站上的解释: https://www.gitkraken.com/learn/git/problems/git-set-upstream-branch#:~:text=With%20GitKraken%2C%20it's%20easy%20to,push%20instead%20of% 20设置%20上游。
As this question is tagged with "gitkraken" here is how you do it in GitKraken:
If you want to push your local branch to a different remote branch only once you can drag and drop your local branch on the remote branch and select "Push local to origin/remote".
The explanation on the GitKraken site: https://www.gitkraken.com/learn/git/problems/git-set-upstream-branch#:~:text=With%20GitKraken%2C%20it's%20easy%20to,push%20instead%20of%20setting%20upstream.