我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
仅三个步骤,以复制名称的更改remote
以及基特胡卜人的故事:
步骤1git branch -m old_branchname new_branchname
步骤2git push origin :old_branchname new_branchname
步骤3git push --set-upstream origin new_branchname
其他回答
在视觉演播室:
· 管理处 _______________________________________________________________________________________________________________________您的仓库 → 您的分支重命名
如果您不想将分支推到远程服务器, 这个示例将很有用 :
假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"
首先,你想改变你的地方分支。
git branch -m my-hot-feature feature-15
更多信息,请访问地方和远程重命名Git的一个分支.
重命名当前分支 :
git branch -m <newname>
将指定给任何分支的分支重新命名 :
git branch -m <oldname> <newname>
-m
短为--move
.
推动地方分支并重设上游分支:
git push origin -u <newname>
删除远程分支 :
git push origin --delete <oldname>
创建git rename
别名 :
git config --global alias.rename 'branch -m'
在 Windows 或其他不区分大小写的文件系统上使用-M
如果名称仅出现资本化变化, 则该名称只有资本化变化 。 否则, Git 将投"部门已经存在"错误 。
git branch -M <newname>
一个简单的方法来做到这一点:
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
更多信息这笔.
到目前为止,答案是正确的,但以下是一些补充信息:
人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :
采用-m或-m或-M选项,
<oldbranch>
将重新命名为<newbranch>
。如果<oldbranch>
具有相应的卷号, 重新命名为匹配<newbranch>
,将创建一个重写条目以记住分支重新命名。如果<newbranch>
存在, -M 必须用于强制重命名 。