我有一个分支主机,它跟踪远程分支源/主机。

我想在本地和远程将它们重命名为master old。这可能吗?

对于跟踪origin/master(并且总是通过git pull更新本地主分支)的其他用户,在我重命名远程分支后会发生什么?他们的git pull是否仍然有效,或者它是否会抛出一个错误,即无法再找到原始/主文件?

接下来,我想创建一个新的主分支(本地和远程)。再次,在我这样做之后,如果其他用户执行git pull,现在会发生什么?

我想这一切都会带来很多麻烦。有没有一种干净的方法可以得到我想要的东西?还是我应该让master保持原样,创建一个新的分支master,然后继续工作?


当前回答

git update-ref newref oldref
git update-ref -d oldref newref

其他回答

转到github.com或其任何位置,单击分支并重命名它。然后在本地运行这些命令:

git branch -m <old-branch-name> <new-branch-name>
git fetch origin
git branch -u origin/<new-branch-name> <new-branch-name>

好的,在本地和远程重命名分支非常简单!。。。

如果你在分支机构,你可以很容易地做到:

gitbranch-m<branch>

否则,您需要执行以下操作:

git分支-m<your_old_branch><your_new_branch>

然后,将删除推送到远程,如下所示:

git推送原点<your_old_branch>

现在你完成了。

如果在尝试推送时遇到上游错误,只需执行以下操作:

git push--设置上游原点<your_new_branch>

我还创建了下图,以显示实际命令行上的步骤。只要按照步骤操作,你就会很好:

关于:

git checkout old-branch-name
git push remote-name new-branch-name
git push remote-name :old-branch-name
git branch -m new-branch-name
git checkout -b new-branch-name
git push remote-name new-branch-name :old-branch-name

在删除旧分支名称之前,您可能必须手动切换到新分支名称

在Git v1.7中,我认为这一点略有改变。现在很容易将本地分支机构的跟踪参考更新到新的远程设备。

git branch -m old_branch new_branch         # Rename branch locally    
git push origin :old_branch                 # Delete the old branch    
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote