问题原因,github创建仓库后默认分支是main,而本地创建是master。所以,提交后发现两个分支,解决步骤如下:
先给本地分支master改名
$ git branch -M main
说明:“-M”对分支重命名
查看所有分支
$ git branch -a
* main
remotes/origin/main
remotes/origin/master
删除远程分支master
$ git push origin --delete master
To <https://github.com/***/learnOpenGL.git>
- [deleted] master
确认删除情况
$ git branch -a
* main
remotes/origin/main
切换到当前分支main,也就要保留下来的分支
$ git checkout main
Already on 'main'
说明:“Already on 'main'”已经说明在当前分支
合并分支
$ git merge remotes/origin/main
fatal: refusing to merge unrelated histories
说明:拒绝合并,需要忽略这个限制,添加“--allow-unrelated-histories”
$ git merge remotes/origin/main --allow-unrelated-histories
Merge made by the 'recursive' strategy.
提交修改
$ git push origin main
Enumerating objects: 34, done.
Counting objects: 100% (34/34), done.
Delta compression using up to 8 threads
Compressing objects: 100% (28/28), done.
Writing objects: 100% (32/32), 1.46 MiB | 1.03 MiB/s, done.
Total 32 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To <https://github.com/test/learnOpenGL.git>
76a2889..d34cf75 main -> main
再次查看分支情况
$ git branch -a
* main
remotes/origin/main
注意:期间可能会弹出一些文本框,直接关闭。