更改本地关联的远程分支?

发布于 2025-01-13 13:30:56 字数 378 浏览 1 评论 0原文

我正在 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?

Branch Diagram

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追我者格杀勿论 2025-01-20 13:30:56

如果你想将本地分支推送到具有不同名称的分支,你只需执行 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.

蓝天 2025-01-20 13:30:56

由于这个问题被标记为“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:

  • right click on the local branch (either in the Graph View or the left side panel)
  • select "Set Upstream"
  • set the remote repo and branch name in the prompt and click "Submit"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文