我刚刚重命名了我的本地分支使用
git branch -m oldname newname
但这只是重命名分支的本地版本。我如何在GitHub上重命名一个?
我刚刚重命名了我的本地分支使用
git branch -m oldname newname
但这只是重命名分支的本地版本。我如何在GitHub上重命名一个?
当前回答
分支重命名现在可以通过GitHub API使用
你可以用GitHub REST API重命名一个分支。
你可以通过gh CLI轻松运行API命令,就像这样:
gh api "repos/{owner}/{repo}/branches/{branch}/rename" -f new_name={newBranch}
其他回答
以下是对我有效的方法:
首先创建新分支: Git推送github newname:refs/heads/newname 在GitHub网站上,进入设置并将默认分支更改为newname 删除oldname Git推送github——删除旧名
你不用终端也能做到。您只需要用新名称创建一个分支,然后删除旧名称。
Create a branch In your repository’s branch selector, just start typing a new branch name. It’ll give you the option to create a new branch: It’ll branch off of your current context. For example, if you’re on the bugfix branch, it’ll create a new branch from bugfix instead of master. Looking at a commit or a tag instead? It’ll branch your code from that specific revision. Delete a branch You’ll also see a delete button in your repository’s Branches page: As an added bonus, it’ll also give you a link to the branch’s Pull Request, if it has one.
我只是复制和粘贴这个内容从:创建和删除分支
下面的命令对我有用:
git push origin :old-name-of-branch-on-github
git branch -m old-name-of-branch-on-github new-name-for-branch-you-want
git push origin new-name-for-branch-you-want
在Git分支中,运行:
git branch -m old_name new_name
这将修改本地存储库中的分支名称:
git push origin :old_name new_name
这将把修改后的名称推到远程并删除旧的分支:
git push origin -u new_name
它设置本地分支来跟踪远程分支。
这就解决了问题。
在Git本地和远程中重命名分支
1. 重命名您的本地分支。
如果你在你想重命名的分支上:
git branch -m new-name
如果你在不同的分支上:
git branch -m old-name new-name
2. 删除旧名称的远程分支,并推送新名称的本地分支。
git push origin :old-name new-name
3.重置新名称本地分支的上游分支。
切换到分支,然后:
git push origin -u new-name
所以结论是:
git branch -m new-name
git push origin :old-name new-name
git push origin -u new-name