我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
有关这一程序的更多详情。
如何在 Git 中重命名本地分支
要重命名当前分支, 请确认您已经检查过当前分支的名称, 并且正在使用您想要重命名的分支 。 git checkout oldbranch 然后 git 分支 - m newbranch 如果您想要, 您可以在另一个分支工作时重新命名一个分支 。 git 分支 - m 旧分支 newbranch
如何重命名 Git 中的远程分支
如果其他用户使用此分支并承诺执行此分支, 您应该在将其重新命名为本地之前将其拉动 。 这样可以确保您的本地仓库得到更新, 并确保其他用户所做的更改不会丢失 。
首先,我们需要从远程仓库删除旧的分机, 并将 enwbranch 推到远程仓库。 git 推车源头 -- delette oldbranch Now 我们将使用 - u (设定的上游) 选项将新分机推到远程 。 git 推车源头 - u newbranch
其他回答
到目前为止,答案是正确的,但以下是一些补充信息:
人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :
在 a - m 或 - M 选项下, < oldbranch > 将重新命名为 < newbranch > 。 如果 < oldbranch > 拥有相应的 reflog, 它将被重新命名为匹配 < newbranch > , 并创建一个 reflog 条目以记住分支重命名。 如果存在 < newbranch > , 则 - 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 branch -m <newname>
将指定给任何分支的分支重新命名 :
git branch -m <oldname> <newname>
- M是短的 -移动。
推动地方分支并重设上游分支:
git push origin -u <newname>
删除远程分支 :
git push origin --delete <oldname>
要创建 git 重命名别名 :
git config --global alias.rename 'branch -m'
在 Windows 或其他不区分大小写的文件系统上, 如果名称中仅出现大小写变化, 请使用 - M 。 否则, Git 会丢弃一个“ 分支已经存在” 错误 。
git branch -M <newname>
如果您想要更改当前分支的名称,请运行 :
git branch -m [old_branch] [new_branch]
如果您想要删除旧的远程分支,请运行 :
git push origin :[old_branch]
如果您想要删除旧的远程分支并创建一个新的远程分支,请运行 :
git push origin :old_branch new_branch
将当前分支重命名为新分支名称 :
git branch -m <new_name>
这将为您正在工作的当前分支设定新名称 。
要重命名另一个分支 :
git branch -m <old_name> <new_name>
您必须在此提供旧的分支名称和新分支名称 。