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

相关:


当前回答

另一个选项是根本不使用命令行。 Git GUI 客户端,例如源树树导致像这个这样的问题 成为Stack overflow最受关注的问题之一。

在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。

其他回答

吉特・伊特的反派命令 试试这个 对我有用

默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。

git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a

高级 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

1. 重命名

如果是您的当前分支, 只需做

git branch -m new_name

如果它是另一个分支, 您想要重命名

git branch -m old_name new_name

2. 跟踪一个新的远程分支

- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :

git push origin :old_name
git push --set-upstream origin new_name

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

  1. 重命名本地 :只需使用以下命令来重命名您当前分支的名称, 即使您检查了 :
    git branch -m <old-branch-name> <new-branch-name>
    
  2. 删除服务器 1 :使用以下命令删除服务器上的旧名称分支 :
    git push <remote-name[origin by default]> :<old-branch-name>
    
  3. 推新的一条:现在该是推动服务器上命名的新分支的时候了:
    git push -u <new-branch-name>
    

重命名本地分支GitHub 桌面桌面,单击现任分处选项卡 (当前仓库右侧) , 右键单击您想要重命名的分支, 右键单击重命名 。 然后您会被弹出提示到可以重命名的位置 。

enter image description here