我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
重命名当前分支 :
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 用户可以手动重命名 :
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
重命名当前分支 :
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>
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a
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 [old-branch] [new-branch]
现在你也必须在远程服务器上传播这些变化。
将已删除的旧分支的更改推到下方 :
git push origin :[old-branch]
推动新分支创建的变更 :
git push origin [new-branch]