我如何重命名尚未被推到远程仓库的本地分支 ?

相关:


当前回答

如果您想要更改当前分支的名称,请运行 :

git branch -m [old_branch] [new_branch]

如果您想要删除旧的远程分支,请运行 :

git push origin :[old_branch]

如果您想要删除旧的远程分支并创建一个新的远程分支,请运行 :

git push origin :old_branch new_branch

其他回答

要重命名您的当前分支 :

git branch -m <newname>

要重命名当前分支( 除独立 HEAD 状态外) 您也可以使用此别名 :

[alias]
    mvh = !sh -c 'git branch -m `git rev-parse --abbrev-ref HEAD` $1'

如果您想要更改当前分支的名称,请运行 :

git branch -m [old_branch] [new_branch]

如果您想要删除旧的远程分支,请运行 :

git push origin :[old_branch]

如果您想要删除旧的远程分支并创建一个新的远程分支,请运行 :

git push origin :old_branch new_branch

高级 Git 用户可以手动重命名 :

Rename the old branch under .git/refs/heads to the new name

Rename the old branch under .git/logs/refs/heads to the new name

Update the .git/HEAD to point to yout new branch name

有关这一程序的更多详情。

如何在 Git 中重命名本地分支

  • 要重命名当前分支, 请确认您已经检查过, 并且正在使用您想要重命名的分支 。
    git checkout oldbranch
    时当时
    git branch -m newbranch
  • 如果您想要,您可以在另一个分支工作时重新命名分支。
    git branch -m oldbranch newbranch

如何重命名 Git 中的远程分支

如果其他用户使用此分支并承诺执行此分支, 您应该在将其重新命名为本地之前将其拉动 。 这样可以确保您的本地仓库得到更新, 并确保其他用户所做的更改不会丢失 。

  • 首先,我们需要删除oldbranch从远程仓库中键,然后按enwbranch至远程。
    git push origin --delete oldbranch

  • 使用-u(固定上游)选项,
    git push origin -u newbranch