我如何重命名尚未被推到远程仓库的本地分支 ?

相关:

重命名本地和远程 Git 仓库的主分支 ?


当前回答

实际上,你有三个步骤 因为本地分行服务器上有一个复制件 所以我们在服务器上的两个步骤上有一个步骤是本地分行:

重命名本地 : 只要使用以下命令重命名您的当前分支, 甚至您检查了它 : git 分支 - m < old- branch- name > < new- branch- name > < new- branch- name > 删除服务器 1 : 使用以下命令删除服务器上的旧名称分支 : git push < remote- name[默认发自] > : <old- branch- name> 推动新分支 : 现在是时候推动服务器上的新分支了 : git push - u < new- branch- name >

其他回答

改变本地分支很容易...

如果您在树枝上, 您想要更改名称, 只需这样做 :

git branch -m my_new_branch

否则,如果你是主人 或任何其他分支 除了你想改名的分支, 简单做:

git branch -m my_old_branch my_new_branch

另外,我在下面创建图像, 以在命令行的操作中显示此图像。 在这种情况下, 您在主分支中, 例如 :

对于 Git GUI 用户来说,它不可能简单得多。 在 Git GUI 中, 从“ 重新命名分支” 对话框创建的“ 重新命名分支” 对话框的向下列表中选择分支名称 : 重新命名, 输入新名称, 单击“ 重新命名 ” 。 我已经突出显示要在哪里找到向下下载列表 。

高级 Git 用户可以手动重命名 :

Rename the old branch under .git/refs/heads to the new name

Rename the old branch under .git/logs/refs/heads to the new name

Update the .git/HEAD to point to yout new branch name

使用此命令重命名分支 :

git branch -m [old_branch_name] [new_branch_name]

- m: 它重命名/ 移动分支。 如果已经有一个分支, 您将会出错 。

如果已经有一个分支, 您想要用该分支重命名, 请使用 :

 git rename -M [old_branch_name] [new_branch_name]

有关帮助的更多信息,请在终端中使用此命令 :

git branch --help

man git branch

如果您想要更改当前分支的名称,请运行 :

git branch -m [old_branch] [new_branch]

如果您想要删除旧的远程分支,请运行 :

git push origin :[old_branch]

如果您想要删除旧的远程分支并创建一个新的远程分支,请运行 :

git push origin :old_branch new_branch