我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
有关这一程序的更多详情。
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
其他回答
git branch -m [old-branch] [new-branch]
-m 意指全部从[旧部门]移动到[新部门],并记住您可以使用 -M 用于其他文件系统。
到目前为止,答案是正确的,但以下是一些补充信息:
人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :
采用-m或-m或-M选项,
<oldbranch>
将重新命名为<newbranch>
。如果<oldbranch>
具有相应的卷号, 重新命名为匹配<newbranch>
,将创建一个重写条目以记住分支重新命名。如果<newbranch>
存在, -M 必须用于强制重命名 。
对于 Git GUI 用户来说,它不可能简单得多。 在 Git GUI 中, 从“ 重新命名分支” 对话框创建的“ 重新命名分支” 对话框的向下列表中选择分支名称 : 重新命名, 输入新名称, 单击“ 重新命名 ” 。 我已经突出显示要在哪里找到向下下载列表 。
在视觉演播室:
· 管理处 _______________________________________________________________________________________________________________________您的仓库 → 您的分支重命名
一个简单的方法来做到这一点:
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
更多信息这笔.