我有一个本地分支主指向一个远程分支原点/regacy(哎呀,拼写错误!)
如何将远程分支重命名为原点/遗留或原点/主?
我试着:
git remote rename regacy legacy
但这给出了一个错误:
错误:不能重命名配置区段的远程。Regacy '到'remote.legacy'
我有一个本地分支主指向一个远程分支原点/regacy(哎呀,拼写错误!)
如何将远程分支重命名为原点/遗留或原点/主?
我试着:
git remote rename regacy legacy
但这给出了一个错误:
错误:不能重命名配置区段的远程。Regacy '到'remote.legacy'
当前回答
检查您正在使用下面的命令的分支
git branch -a
签出到要重命名的分支
git checkout branch_to_rename
使用以下命令重命名分支
git branch -m new_name
推动改变
git push origin :old_name new_name
其他回答
首先,确保本地分支具有正确的新名称。 相应的命令是git branch -a。
现在,从远程存储库中删除具有旧的、不正确的名称的分支。 为此,使用以下命令 Git push origin——delete <old-name>
验证旧的分支已经被正确地删除。 现在添加具有正确名称的分支。 为此,使用命令git push origin -u <new-name>
最后,执行上游分支的重置,以确保更改是有效的。
有几种方法可以做到这一点:
更改您的本地分支,然后推动您的更改 使用新名称将分支推到远程,同时在本地保留原始名称
重命名本地和远程
# Rename the local branch to the new name
git branch -m <old_name> <new_name>
# Delete the old branch on remote - where <remote> is, for example, origin
git push <remote> --delete <old_name>
# Or shorter way to delete remote branch [:]
git push <remote> :<old_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>
# Push the new branch to remote
git push <remote> <new_name>
# Reset the upstream branch for the new_name local branch
git push <remote> -u <new_name>
只重命名远程分支
信用:ptim
# In this option, we will push the branch to the remote with the new name
# While keeping the local name as is
git push <remote> <remote>/<old_name>:refs/heads/<new_name> :<old_name>
重要提示:
当你使用git分支-m (move)时,git也会用新名称更新你的跟踪分支。
Git远程重命名遗留遗留
Git远程重命名正在尝试更新配置文件中的远程部分。它将使用给定名称将远程重命名为新名称,但在您的示例中,它没有找到任何名称,因此重命名失败。
但它不会像你想的那样;它将重命名本地配置远程名称,而不是远程分支。
请注意 Git服务器可能允许你使用web界面或外部程序(如Sourcetree等)重命名Git分支,但你必须记住,在Git中所有的工作都是在本地完成的,所以建议使用上述命令来工作。
重命名您的本地分支。
如果你在你想重命名的分支上:
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
托管在GitHub上的Git存储库中的分支可以使用存储库设置重命名。作为一个副作用,GitHub中的分支保护规则也将被改变。
访问存储库设置中的“分支”:https://github.com/<name>/<repository-name>/settings/ Branches 重命名分支 每个使用这个存储库的人都必须在本地做:
$ git获取 $ git checkout <new_name>
似乎有一个直接的方法:
如果您真的只想远程重命名分支(而不同时重命名任何本地分支),您可以使用如下命令来完成此操作 Git push <remote> <remote>/<old_name>:refs/heads/<new_name>:<old_name> 在Git中远程重命名分支
详见原文。