我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 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
其他回答
1. 重命名
如果是您的当前分支, 只需做
git branch -m new_name
如果它是另一个分支, 您想要重命名
git branch -m old_name new_name
2. 跟踪一个新的远程分支
- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :
git push origin :old_name
git push --set-upstream origin new_name
重命名当前分支 :
git branch -m <newname>
将指定给任何分支的分支重新命名 :
git branch -m <oldname> <newname>
- M是短的 -移动。
推动地方分支并重设上游分支:
git push origin -u <newname>
删除远程分支 :
git push origin --delete <oldname>
要创建 git 重命名别名 :
git config --global alias.rename 'branch -m'
在 Windows 或其他不区分大小写的文件系统上, 如果名称中仅出现大小写变化, 请使用 - M 。 否则, Git 会丢弃一个“ 分支已经存在” 错误 。
git branch -M <newname>
改变本地分支很容易...
如果您在树枝上, 您想要更改名称, 只需这样做 :
git branch -m my_new_branch
否则,如果你是主人 或任何其他分支 除了你想改名的分支, 简单做:
git branch -m my_old_branch my_new_branch
另外,我在下面创建图像, 以在命令行的操作中显示此图像。 在这种情况下, 您在主分支中, 例如 :
调
将当前分支重命名为新分支名称 :
git branch -m <new_name>
这将为您正在工作的当前分支设定新名称 。
要重命名另一个分支 :
git branch -m <old_name> <new_name>
您必须在此提供旧的分支名称和新分支名称 。
如果您想要:
重命名 Git 仓库, 运行 : git 分支 - m <oldname> < newname> 以下列方式删除旧分支 : git 推进源 : 旧名称的新名称使用 : git 承诺 < newname> , 然后使用 : git 推进源 New_ branch_ name: master 如果您想要检查状态, 那么使用 : git 状态 如果您想要检查是否退出, 那么使用: git 检查退出