我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
使用此命令重命名分支 :
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 用户可以手动重命名 :
Rename the old branch under .git/refs/heads to the new name
Rename the old branch under .git/logs/refs/heads to the new name
Update the .git/HEAD to point to yout new branch name
另一个选项是完全不使用命令行。 Git GUI 客户端, 如 SourceTree , 拿走了导致像此这样的问题成为Stack 溢流中最受关注的问题的学习周期曲线 / 疼痛 。
在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。
之前所有的答案都在谈论 Git 分支- m。 当然,这很容易操作, 但对我来说, 可能很难记住另一个 Git 命令。 所以我试图让我熟悉的指令完成它的工作。 是的,你可能猜到了。
我使用 git 分支 -b <new_branch_name>。 如果您现在不想保存旧分支, 您可以执行 git 分支 -D <old_branch_name> 来删除它 。
我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。
您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。
从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。
从多个国家引出 - 在 Git 中重命名本地和远程分支
1. 重新命名您的本地分支
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
2. 删除旧名称远程分支,并按下新名称本地分支
git push origin :old-name new-name
3. 重新设置新命名地方分支的上游分支
git push origin -u new-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