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

相关:

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


当前回答

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

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 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>
git branch -m old_branch_name new_branch_name

上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。

如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :

git push 源新\ branch_ name : master (现在更改将转到母版分支, 但您本地的分支名称是新_ branch_ name )

详情请见“如何在 Git 中重新命名您的本地分支名称 ” 。

要重命名本地分支 :

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

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

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

git push origin :[old-branch]

推动新分支创建的变更 :

git push origin [new-branch]

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

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 branch -m <newname>