问题
在 git
仓库中新建了一个仓库,想要把本地的工程目录推送上去:
1 | git init |
添加远程 git
仓库:
1 | git remote add origin https://<access_token>@github.com/sakishum/xxx.git |
推送到远程仓库:
1 | git push origin main |
提示错误:
1 | git push -u origin main |
按照提示先拉取更新,但提示报错:
1 | git pull origin main |
解决方法
在拉取分支时使用以下命令:
1 | git pull origin main --allow-unrelated-histories |
之后在执行:
1 | git push origin main |
原因
对此问题,官方的解释如下:
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.
以上。