我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
高级 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 <new_name>
这将为您正在工作的当前分支设定新名称 。
git branch -m <old_name> <new_name>
您必须在此提供旧的分支名称和新分支名称 。
如果您想要更改分支的名称
git 分支 - m 新名称
如果是您的当前分支, 只需做
git branch -m new_name
如果它是另一个分支, 您想要重命名
git branch -m old_name new_name
- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :
git push origin :old_name
git push --set-upstream origin new_name
一个简单的方法来做到这一点:
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
更多信息这笔.
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a