我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
要重命名当前分支( 除独立 HEAD 状态外) 您也可以使用此别名 :
[alias]
mvh = !sh -c 'git branch -m `git rev-parse --abbrev-ref HEAD` $1'
其他回答
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a
实际上,你有三个步骤 因为本地分行服务器上有一个复制件 所以我们在服务器上的两个步骤上有一个步骤是本地分行:
git branch -m <old-branch-name> <new-branch-name>
git push <remote-name[origin by default]> :<old-branch-name>
git push -u <new-branch-name>
更改事务组本地本地很简单...
如果您在树枝上, 您想要更改名称, 只需这样做 :
git branch -m my_new_branch
否则,如果你在master
或任何其他事务组而不是你想改名的,简单说说:
git branch -m my_old_branch my_new_branch
此外,我创建了下面的图像 来展示在命令行。在这种情况下,你正在master
例如,分支:
有关这一程序的更多详情。
git checkout oldbranch
git branch -m newbranch
git branch -m oldbranch newbranch
如果其他用户使用此分支并承诺执行此分支, 您应该在将其重新命名为本地之前将其拉动 。 这样可以确保您的本地仓库得到更新, 并确保其他用户所做的更改不会丢失 。
首先,我们需要删除oldbranch
从远程仓库中键,然后按enwbranch
至远程。
git push origin --delete oldbranch
使用-u(固定上游)选项,
git push origin -u newbranch
到目前为止,答案是正确的,但以下是一些补充信息:
人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :
采用-m或-m或-M选项,
<oldbranch>
将重新命名为<newbranch>
。如果<oldbranch>
具有相应的卷号, 重新命名为匹配<newbranch>
,将创建一个重写条目以记住分支重新命名。如果<newbranch>
存在, -M 必须用于强制重命名 。