我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。
从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
git push origin :old-name new-name
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
更多信息这笔.
所有你必须做的是三步:
.git/refs/heads
新名称.git/logs/refs/heads
新名称.git/HEAD
导致您新分支名称git branch -m <new_name>
这将为您正在工作的当前分支设定新名称 。
git branch -m <old_name> <new_name>
您必须在此提供旧的分支名称和新分支名称 。
有关这一程序的更多详情。
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
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a