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

相关:


当前回答

要重命名当前分支( 除独立 HEAD 状态外) 您也可以使用此别名 :

[alias]
    mvh = !sh -c 'git branch -m `git rev-parse --abbrev-ref HEAD` $1'

其他回答

使用此命令重命名分支 :

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

以下是重新命名分支的步骤 :

  1. 切换到需要重新命名的分支
  2. git branch -m <new_name>
  3. git push origin :<old_name>
  4. git push origin <new_name>:refs/heads/<new_name>

EDIT(12/01/2017):确保您运行命令git status并检查新创建的分支指向的是它自己的参考文献,而不是旧的参考文献。如果找到旧分支的引用文献,您需要解开上游的设置,使用 :

git branch --unset-upstream

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

git branch -m [old_branch] [new_branch]

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

git push origin :[old_branch]

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

git push origin :old_branch new_branch

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

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

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

一个简单的方法来做到这一点:

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

更多信息这笔.