如何重命名本地 Git 分支? [英] How do I rename a local Git branch?
问题描述
我不想重命名远程分支,如重命名本地和远程 Git 存储库的主分支.
如何重命名尚未推送到远程存储库的本地分支?
如果您还需要重命名远程分支:
如何重命名 Git 本地和远程分支名称?
如果您想在指向任何分支时重命名分支,请执行以下操作:
git branch -m <新名称>
如果要重命名当前分支,可以这样做:
git branch -m <新名称>
如果要推送本地分支并重置上游分支:
git push origin -u <新名称>
最后如果你想删除远程分支:
git push origin --delete
记住这一点的方法是 -m
表示移动";(或 mv
),这是您重命名文件的方式.添加别名也有帮助.为此,请运行以下命令:
git config --global alias.rename 'branch -m'
如果你在 Windows 或其他不区分大小写的文件系统上,并且名称只有大小写变化,则需要使用 -M
,否则,git 会抛出 分支已经存在 错误:
git branch -M <新名称>
I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.
How can I rename a local branch which hasn't been pushed to a remote repository?
In case you need to rename a remote branch as well:
How do I rename both a Git local and remote branch name?
If you want to rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
If you want to push the local branch and reset the upstream branch:
git push origin -u <newname>
And finally if you want to Delete the remote branch:
git push origin --delete <oldname>
A way to remember this is -m
is for "move" (or mv
), which is how you rename files. Adding an alias could also help. To do so, run the following:
git config --global alias.rename 'branch -m'
If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use -M
, otherwise, git will throw branch already exists error:
git branch -M <newname>
这篇关于如何重命名本地 Git 分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!