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

# delete the old branch on remote - where is eg. origin

git push --delete old_name

# push the new branch to remote

git push new_name

fb0928aa967423b37156e458731c3c21.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值