【发布时间】:2022-08-09 16:15:29
【问题描述】:
有人在 Github 上重命名了我已经有一些未推送的提交的分支,现在我无法推送它们,因为该分支不存在。我不想更改新的远程分支名称,我只想适应我的本地分支。只是重命名分支不起作用,因为 git 仍然想推送到相同的旧分支名称。
标签: git github gitlab bitbucket
有人在 Github 上重命名了我已经有一些未推送的提交的分支,现在我无法推送它们,因为该分支不存在。我不想更改新的远程分支名称,我只想适应我的本地分支。只是重命名分支不起作用,因为 git 仍然想推送到相同的旧分支名称。
标签: git github gitlab bitbucket
我从here 发现了解决方案。诀窍很简单,只需在推送之前执行以下几行:
# Rename the local branch to the new name
git branch -m <old_name> <new_name>
# Prevent git from using the old name when pushing in the next step.
# Otherwise, git will use the old upstream name instead of <new_name>.
git branch --unset-upstream <new_name>
我以其他格式重新发布此内容,因为问题不同,并且对某人有用。
【讨论】: