我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
要重命名您的当前分支 :
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
更多,看看这个。
1. 重命名
如果是您的当前分支, 只需做
git branch -m new_name
如果它是另一个分支, 您想要重命名
git branch -m old_name new_name
2. 跟踪一个新的远程分支
- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :
git push origin :old_name
git push --set-upstream origin new_name
重命名本地分支 : git 分支 -m <old_branch_name_name> <new_branch_name> 按下新分支 : git 推 -- set- 上流来源 < new_ branch_ name>
所有你必须做的是三步:
在.git/refs/head 下给旧分支以.git/refs/head 下的新名称 给旧分支以.git/log/refs/head 下的新名称 更新 .git/HEAD 以导致您的新分支名称 。