我有一个带有一些提交的本地仓库。由于我想将其公开给其他人,我需要将其推送到 Github 上新创建的远程仓库。新创建的远程仓库使用许可文件初始化(因为本地仓库没有许可文件)。
由于在远程仓库中添加了文件,因此推送git push -u origin main
(我的本地分支也使用main
而不是master
作为主分支)会产生错误。license
C:\test>git push -u origin main
To https://github.com/pstricks-fans/test.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/pstricks-fans/test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我按照以下提示进行拉动。
C:\test>git pull origin main
From https://github.com/pstricks-fans/test
* branch main -> FETCH_HEAD
fatal: refusing to merge unrelated histories
合并是不可能的。
有人告诉我,我必须使用以下内容重新设置基础。
C:\test>git pull origin main --rebase
From https://github.com/pstricks-fans/test
* branch main -> FETCH_HEAD
Successfully rebased and updated refs/heads/main.
问题
有没有其他没有变基的解决方案(出于学习目的)?不建议对公共 repo 进行变基(如 git 文档所述)。