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

相关:


当前回答

如果您想要:

  • 重命名 Git 仓库, 运行 :git branch -m <oldname> <newname>
  • 删除旧分支 :git push origin: old-name new-name
  • 提交使用 :git commit <newname>
    • 并按下使用 :git push origin new_branch_name:master
  • 如果您想要检查状态, 请使用 :git status
  • 如果您想要检查退出, 请使用 :git checkout

其他回答

一个简单的方法来做到这一点:

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

更多信息这笔.

可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。

如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:

$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.

然后,你必须做一个中间步骤:

$ git branch -m temporary
$ git branch -m casesensitive

仅此而已。

使用此命令重命名分支 :

git branch -m [old_branch_name] [new_branch_name]

-m:它重命名/移动分支。如果已经有一个分支,则会出错。

如果已经有一个分支, 您想要用该分支重命名, 请使用 :

 git rename -M [old_branch_name] [new_branch_name]

有关帮助的更多信息,请在终端中使用此命令 :

git branch --help

man git branch

所有你必须做的是三步:

  1. 给旧分支下.git/refs/heads新名称
  2. 给旧分支下.git/logs/refs/heads新名称
  3. 更新.git/HEAD导致您新分支名称

要重命名您的当前分支 :

git branch -m <newname>