重命名远程git分支 [英] Renaming remote git branch

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

问题描述

我有2个git分支:master和experimental。

实验变得很好,我想让它成为主人。我想我会重命名为洗牌的东西,但这里是我得到的:

  nutebook:Stuff nathan $ git remote rename master旧
错误:无法将配置节'remote.master'重命名为'remote.old'

我使用GitHub和Git-Tower。

解决方案

以下是重命名主分支的指南。它可以轻松地重新命名实验分支。


以下是我进行重命名的过程。



首先,在工作树中,将master重命名为
else。

  git分支-m master old-dev 

重命名分支可以在分支上工作,所以

$ b

然后,将维护分支(2.63分支)本地重命名为
master:

  git branch -m 2.63分支大师

现在,时间与遥控器混淆了。万一你搞砸了,你
可能想要确保你有一个当前的备份。首先,删除
remote的master:

  git push origin:master 

现在,给远程您的新主人:

  git push origin master:refs / heads / master 

更新:创建新分支时,在远程端需要
的refs / heads / prefix。如果分支已经存在(主人做
以上),那么只需要远程端的分支名称。



...和您现在更名的旧master:

  git push origin old-dev:refs / heads / old-dev 



最后,删除您的维护分支的旧名称以防止
混淆:

  git push origin:2.63分支

获得'新'主分支时,他们拉。


请参阅这个网站。


I have 2 git branches: master and experimental.

Experimental became good, I want to make it the master. I figured I would rename to shuffle things around, but here is what I got:

nutebook:Stuff nathan$ git remote rename master old
error: Could not rename config section 'remote.master' to 'remote.old'

I use GitHub and Git-Tower.

解决方案

The following is a guide to rename your master branch. It will work just as easily to rename your experimental branch.

Here's how I did the renaming.

First, in your working tree, locally rename master to something else.

git branch -m master old-dev

Renaming a branch does work while you are on the branch, so there's no need to checkout something else.

Then, locally rename the maintenance branch (2.63-branch) to master:

git branch -m 2.63-branch master

Now, time to mess with the remote. Just in case you screw up, you might want to make sure you have a current backup. First, delete the remote's master:

git push origin :master

And now, give the remote your new master:

git push origin master:refs/heads/master

Update: When creating a new branch, the refs/heads/ prefix is needed on the remote side. If the branch already exists (as master did above) only the branch name is required on the remote side.

... and your now-renamed old master:

git push origin old-dev:refs/heads/old-dev

Finally, delete the old name of your maintenance branch to prevent confusion:

git push origin :2.63-branch

Clients will now get the 'new' master branch when they pull.

see this site.

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

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