我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
如果您想要:
重命名 Git 仓库, 运行 : git 分支 - m <oldname> < newname> 以下列方式删除旧分支 : git 推进源 : 旧名称的新名称使用 : git 承诺 < newname> , 然后使用 : git 推进源 New_ branch_ name: master 如果您想要检查状态, 那么使用 : git 状态 如果您想要检查是否退出, 那么使用: git 检查退出
其他回答
要重命名本地分支 :
git branch -m [old-branch] [new-branch]
现在你也必须在远程服务器上传播这些变化。
将已删除的旧分支的更改推到下方 :
git push origin :[old-branch]
推动新分支创建的变更 :
git push origin [new-branch]
重新命名您的本地分支 。
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
删除旧名称远程分支并按下新名称本地分支 。
git 推推源: old- name new- name
重置新命名本地分支的上游分支。 切换到分支, 然后 :
git 推进源 - u new- name
或者为了快速地做到这一点 你可以使用这三步:
# 本地重命名分支
git branch -m old_branch new_branch
# 删除旧的远程分支
git push origin :old_branch
# 推动新分支, 设置本地分支以跟踪新远程
git push --set-upstream origin new_branch
参考文献:https://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html
高级 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 branch -m [old-branch] [new-branch]
-m 意指全部从[旧部门]移动到[新部门],并记住您可以使用 -M 用于其他文件系统。
如果您不想将分支推到远程服务器, 这个示例将很有用 :
假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"
首先,你想改变你的地方分支。
git branch -m my-hot-feature feature-15
若想了解更多信息,请访问Git的本地和远程重命名分部。