我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
之前所有的答案都在谈论git branch -m
。 当然, 操作很容易, 但对我来说, 可能很难记住另一个 Git 命令 。 所以我试图完成我熟悉的指令。 是的, 你可能猜到了 。
我用的是git branch -b <new_branch_name>
。如果你不想保存旧的分支,现在你可以执行git branch -D <old_branch_name>
要删除它。
我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。
其他回答
使用此命令重命名分支 :
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
要重命名您的当前分支 :
git branch -m <newname>
2.9.2 Git 版本
如果您想要更改本地分支的名称, 请在 :
git branch -m new_name
如果您想要更改另一分支的名称 :
git branch -m old_name new_name
如果您想要将其它分支的名称更改为已经存在的名称 :
git branch -M old_name new_name_that_already_exists
注意: 最后一个命令是破坏性的, 将会重新命名您的分支, 但是您会丢失旧分支, 并且会丢失旧分支, 因为分支名称必须是独一无二的 。
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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 分支名称这是一篇关于这个的好文章。
如果您不想将分支推到远程服务器, 这个示例将很有用 :
假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"
首先,你想改变你的地方分支。
git branch -m my-hot-feature feature-15
更多信息,请访问地方和远程重命名Git的一个分支.