在Git中远程重命名分支 [英] Renaming branches remotely in Git

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

问题描述

如果有一个我只能访问 git:// 的存储库(通常只是push + pull),是否可以在其中重命名分支存储库,就像我在本地使用 git branch -m 一样?

If there is a repository that I only have git:// access to (and would usually just push+pull), is there a way to rename branches in that repository in the same way that I would do locally with git branch -m?

推荐答案

您只需要创建一个具有所需名称的新本地分支,将其推送到您的远程分支,然后删除旧的远程分支:

You just have to create a new local branch with the desired name, push it to your remote, and then delete the old remote branch:

$ git branch new-branch-name origin/old-branch-name
$ git push origin --set-upstream new-branch-name
$ git push origin :old-branch-name

然后,要查看旧的分支名称,存储库的每个客户端都必须做:

Then, to see the old branch name, each client of the repository would have to do:

$ git fetch origin
$ git remote prune origin

注意:如果旧分支是主分支,则应更改主分支设置。否则,当您运行 $ git push origin:old-branch-name 时,会出现错误禁止删除当前分支

NOTE: If your old branch is your main branch, you should change your main branch settings. Otherwise, when you run $ git push origin :old-branch-name, you'll get the error "deletion of the current branch prohibited".

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

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