我有一个本地分支主指向一个远程分支原点/regacy(哎呀,拼写错误!)

如何将远程分支重命名为原点/遗留或原点/主?


我试着:

git remote rename regacy legacy

但这给出了一个错误:

错误:不能重命名配置区段的远程。Regacy '到'remote.legacy'


当前回答

附加一个简单的片段来重命名你的当前分支(本地的和原始的):

git branch -m <oldBranchName> <newBranchName>
git push origin :<oldBranchName>
git push --set-upstream origin <newBranchName>

git文档中的解释:

git branch -m or -M option, will be renamed to . If had a corresponding reflog, it is renamed to match , and a reflog entry is created to remember the branch renaming. If exists, -M must be used to force the rename to happen. The special refspec : (or +: to allow non-fast-forward updates) directs Git to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. --set-upstream Set up 's tracking information so is considered 's upstream branch. If no is specified, then it defaults to the current branch.

其他回答

它也可以通过以下方式完成。

首先重命名本地分支,然后重命名远程分支。

重命名本地分支:

如果登录到另一个分支,

git branch -m old_branch new_branch 

如果登录到同一个分支,

git branch -m new_branch

重命名远程分支:

git push origin :old_branch    // Delete the remote branch

git push --set-upstream origin new_branch   // Create a new remote branch

重命名您的本地分支。

如果你在你想重命名的分支上:

git branch -m new-name

如果你当前停留在不同的分支上:

git branch -m old-name new-name

删除旧名称的远程分支,并推送新名称的本地分支。

停留在目标分支上,然后:

git push origin :old-name new-name

重置新名称本地分支的上游分支。

切换到目标分支,然后:

git push origin -u new-name

首先,确保本地分支具有正确的新名称。 相应的命令是git branch -a。

现在,从远程存储库中删除具有旧的、不正确的名称的分支。 为此,使用以下命令 Git push origin——delete <old-name>

验证旧的分支已经被正确地删除。 现在添加具有正确名称的分支。 为此,使用命令git push origin -u <new-name>

最后,执行上游分支的重置,以确保更改是有效的。

重命名本地分支

 git branch -m <old_name> <new_name>

将本地分支从master重命名为legacy

git branch -m master legacy

重命名远程分支

删除使用旧名称的远程分支 将具有新名称的本地分支推到远程存储库

git push origin :regacy

git push origin legacy

Git push origin:regacy删除名为regacy的远程分支。 Git push origin legacy将名为legacy的本地分支推到远程存储库,并创建一个名为legacy的新远程分支。

似乎有一个直接的方法:

如果您真的只想远程重命名分支(而不同时重命名任何本地分支),您可以使用如下命令来完成此操作 Git push <remote> <remote>/<old_name>:refs/heads/<new_name>:<old_name> 在Git中远程重命名分支

详见原文。