我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a
其他回答
我愚蠢地命名了一个树枝 从连字符开始, 然后检查了主人。删除删除我的分支,我有工作在里面。
这两种办法都行不通:
git checkout -dumb-name
git checkout -- -dumb-name
"
s,'
s 和 s , s 和 s\
也没有帮助。git branch -m
没有工作。
我终于把它修好了。 进入您的工作副本 . git/ refs/ heads, 找到文件名“ - dumb- name ” , 获取分支的大麻。 然后, 这将检查它, 制造一个新的有正常名称的分支, 并删除旧的分支 。
git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name
git branch -m [old-branch] [new-branch]
-m 意指全部从[旧部门]移动到[新部门],并记住您可以使用 -M 用于其他文件系统。
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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
如果需要更多的话:一步一步,如何更改 Git 分支名称这是一篇关于这个的好文章。
有关这一程序的更多详情。
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
。 当然, 操作很容易, 但对我来说, 可能很难记住另一个 Git 命令 。 所以我试图完成我熟悉的指令。 是的, 你可能猜到了 。
我用的是git branch -b <new_branch_name>
。如果你不想保存旧的分支,现在你可以执行git branch -D <old_branch_name>
要删除它。
我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。