我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
对于 Git GUI 用户来说,它不可能简单得多。 在 Git GUI 中, 从“ 重新命名分支” 对话框创建的“ 重新命名分支” 对话框的向下列表中选择分支名称 : 重新命名, 输入新名称, 单击“ 重新命名 ” 。 我已经突出显示要在哪里找到向下下载列表 。
其他回答
要重命名您的当前分支 :
git branch -m <newname>
Git 分支重命名可以使用 :
git branch -m oldBranch newBranch
git branch -M oldBranch ExistingBranch
和(或)- 中 - 中和- MM,MM,MM,MM,MM,M:
- 毫米:如果您试图用现有的分支名称重命名您的分支- 中 - 中。它会引出一个错误,表示分支已经存在。您需要给出独有的名称。
但是,
- 男: - 男: - 女: - M:这将帮助您强制重命名一个指定的名称, 即使它已经存在 。 因此一个已有的分支将完全覆盖它...
这儿有一个吉特终点的例子,
mohideen@dev:~/project/myapp/sunithamakeup$ git branch
master
master0
new_master
test
* test1
mohideen@dev:~/project/myapp/sunithamakeup$ git branch -m test1 test
fatal: A branch named 'test' already exists.
mohideen@dev:~/project/myapp/sunithamakeup$ git branch -M test1 test
mohideen@dev:~/project/myapp/sunithamakeup$ git branch
master
master0
new_master
* test
mohideen@dev:~/project/myapp/sunithamakeup$
git branch -m old_branch_name new_branch_name
上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。
如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :
git push origin new_branch_name:master
(现在更改将转到母版分支, 但您的本地分支名称是新_ branch_ name)
详情见 " 。如何在 Git 中重新命名您的本地分支名称."
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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 分支名称这是一篇关于这个的好文章。
高级 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