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

相关:


当前回答

您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。

从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。

引引自多州 - 在 Git 中重命名本地和远程分支

1. 重新命名您的本地分支

如果您在分支上, 您想要重命名 :

git branch -m new-name

如果在另一分支上:

git branch -m old-name new-name

2. 删除旧名称远程分支,并按下新名称本地分支

git push origin :old-name new-name

3. 重新设置新命名地方分支的上游分支

git push origin -u new-name

其他回答

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

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

更多信息这笔.

所有你必须做的是三步:

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

将当前分支重命名为新分支名称 :

git branch -m <new_name>

这将为您正在工作的当前分支设定新名称 。


要重命名另一个分支 :

git branch -m <old_name> <new_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

吉特・伊特的反派命令 试试这个 对我有用

默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。

git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a