如何重命名远程git分支名称 [英] How to rename a remote git branch name

查看:1011
本文介绍了如何重命名远程git分支名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个braches,像master - > origin / regacy,featureA - > origin / FeatureA。

正如您在上面看到的,我输入了错误的名称。



所以我想重命名一个远程分支名称(origin / regacy => origin / legacy或origin / master)

我试着在下面命令。


git remote rename regacy legacy


但是git控制台对我隐瞒了错误信息。


错误:无法重命名config部分'remote。 regacy'to
'remote.legacy'


我该如何解决这个问题?


您不能直接重命名远程分支。

您必须先删除它,然后重新命名该分支。

推它。



重命名分支



 #将本地分支重命名为新分支名称
git分支-m< old_name> < NEW_NAME>

#删除远程的旧分支 - 其中< remote>是例如。原产地
git push< remote> --delete old_name

#将新分支推送到远程
git push< remote> new_name






重要提示:



当您使用 git branch -m (移动),git也使用新名称更新您的跟踪分支。


git remote rename regacy legacy


git远程重命名正在尝试更新配置文件中的远程节。它会将给定名称的远程名称重新命名为新名称,但在您的情况下它没有找到任何名称,因此重命名失败。



但您的想法并不符合您的想法,而不是远程分支。 






注意
Git服务器可能允许您使用Web界面或外部程序(如Sourctree等)重命名git分支,但是您必须记住,在git中,所有工作均在本地完成,因此建议您使用上述命令进行工作。


I have 4 braches like master -> origin/regacy, FeatureA -> origin/FeatureA.

As you can see above, I typed a wrong name.

So I want to rename a remote branch name ( origin/regacy => origin/legacy or origin/master)

I try to command below.

git remote rename regacy legacy

But git console retured error msg to me.

error : Could not rename config section 'remote.regacy' to 'remote.legacy'

How can i solve this problem?

解决方案

You can't directly rename a remote branch.
You have to delete it and then re-push it.

Renaming a branch

# rename the local branch to the new name
git branch -m <old_name> <new_name> 

# delete the old branch on remote - where <remote> is eg. origin
git push <remote> --delete old_name

# push the new branch to remote         
git push <remote> new_name


Important note :

When you use the git branch -m (move), git is also updating your tracking branch with the new name.

git remote rename regacy legacy

git remote rename is trying to update your remote section in your config file. It will rename the remote with the given name to the new name, but in your case it did not find any, so the renaming failed.

But it will not do what you think, it will rename your local config remote name and not the remote branch. 


Note Git servers might allow you to rename git branch using the web interface or external programs (like Sourctree etc) but you have to keep in mind that in git all the work is done locally so its recommended to use the above commands to the work.

这篇关于如何重命名远程git分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆