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

相关:

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


当前回答

如果您不想将分支推到远程服务器, 这个示例将很有用 :

假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"

首先,你想改变你的地方分支。

git branch -m my-hot-feature feature-15

若想了解更多信息,请访问Git的本地和远程重命名分部。

其他回答

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

git branch -m [old_branch] [new_branch]

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

git push origin :[old_branch]

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

git push origin :old_branch new_branch

只要三步即可在远程和GitHub复制名称变化:

第 1 步 git 分支 - m 旧的Branchname new_ branchname

步骤 2 git 推进源 : old_ branchname new_ branchname

步骤 3 git 推进 - 设置上流源新分支名

要重命名本地分支 :

git branch -m [old-branch] [new-branch]

现在你也必须在远程服务器上传播这些变化。

将已删除的旧分支的更改推到下方 :

git push origin :[old-branch]

推动新分支创建的变更 :

git push origin [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 <newname>

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

git branch -m <oldname> <newname>

- M是短的 -移动。


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

git push origin -u <newname>

删除远程分支 :

git push origin --delete <oldname>

要创建 git 重命名别名 :

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

在 Windows 或其他不区分大小写的文件系统上, 如果名称中仅出现大小写变化, 请使用 - M 。 否则, Git 会丢弃一个“ 分支已经存在” 错误 。

git branch -M <newname>