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

相关:


当前回答

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

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

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

其他回答

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

  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>
    

如果您想要:

  • 重命名 Git 仓库, 运行 :git branch -m <oldname> <newname>
  • 删除旧分支 :git push origin: old-name new-name
  • 提交使用 :git commit <newname>
    • 并按下使用 :git push origin new_branch_name:master
  • 如果您想要检查状态, 请使用 :git status
  • 如果您想要检查退出, 请使用 :git checkout

到目前为止,答案是正确的,但以下是一些补充信息:

人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :

采用-m或-m或-M选项,<oldbranch>将重新命名为<newbranch>。如果<oldbranch>具有相应的卷号, 重新命名为匹配<newbranch>,将创建一个重写条目以记住分支重新命名。如果<newbranch>存在, -M 必须用于强制重命名 。

这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。

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

如果需要更多的话:一步一步,如何更改 Git 分支名称这是一篇关于这个的好文章。

重命名当前分支 :

git branch -m <newname>

将指定给任何分支的分支重新命名 :

git branch -m <oldname> <newname>

-m短为--move.


推动地方分支并重设上游分支:

git push origin -u <newname>

删除远程分支 :

git push origin --delete <oldname>

创建git rename别名 :

git config --global alias.rename 'branch -m'

在 Windows 或其他不区分大小写的文件系统上使用-M如果名称仅出现资本化变化, 则该名称只有资本化变化 。 否则, Git 将投"部门已经存在"错误 。

git branch -M <newname>