如何在github上将主分支移动到主分支

如何在github上将主分支移动到主分支,github,Github,我在git hub中有一个主分支和一个主分支。这不是故意的,我意识到我一直在和师父一起努力,所以一切都交给了师父。然而,GitHub现在使用main而不是master作为第一个位置。如何将主分支移动到主分支?在GitHub Web界面中创建从主分支到主分支的PR。 如果要在本地执行此操作,请执行以下操作: git签出主 git合并主机 git push将其推送到GitHub的主分支中。实现这一点有多种方法,但使用纯git可以按如下方式完成: #Change to the main branch

我在git hub中有一个主分支和一个主分支。这不是故意的,我意识到我一直在和师父一起努力,所以一切都交给了师父。然而,GitHub现在使用main而不是master作为第一个位置。如何将主分支移动到主分支?

在GitHub Web界面中创建从主分支到主分支的PR。 如果要在本地执行此操作,请执行以下操作:

git签出主

git合并主机


git push将其推送到GitHub的主分支中。

实现这一点有多种方法,但使用纯git可以按如下方式完成:

#Change to the main branch
git checkout main
#Rebase the main branch on top of the current master. In easy words, go to the last point the two branches have in common, then add all the changes master did in the meanwhile and then add the changes done to main. If main is empty this is equivalent to 
# git checkout master; git branch -D main; git checkout -b main
#which deletes the current main and then copies master over to main
git rebase master
# push back to GitHub (--force, because rabse does not add a commit, but changes the status, so push will be rejected without it)
git push --force

通过访问,您可以通过github web界面删除或重命名分支

https://github.com/YourName/YourRepo/branches
撰写本文时,您可以通过
分支机构
链接从存储库的首页访问该页面:

您可以单击书写工具按钮重命名其关联的分支:


值得注意的是,通过github删除和重命名分支与使用CLI git或GUI git客户端一样具有潜在的破坏性。当然,您可以从本地克隆重新推送分支,但如果您不确定,在继续之前,您应该确保克隆是最新的。

您能解释一下这是做什么的,以及为什么它可以解决问题吗?