git push 被拒绝,拉取失败:致命:拒绝合并不相关的历史

Ask*_*skQ 2 git github

我在 Github 控制台上创建了新的 Repo。
在 Android Studio 中,提交并尝试推送到远程,推送被拒绝。

在studio,我可以成功连接github。

尝试使用 android studio 进行 Git pull,得到:

Git Pull Failed: fatal: refusing to merge unrelated histories
Run Code Online (Sandbox Code Playgroud)

即使在 git bash 中也得到了这个:

>git push origin master<br/>
To https://github.com/XXXX.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/XXX.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.
Run Code Online (Sandbox Code Playgroud)

Ask*_*skQ 6

In Android Studio,
Run Code Online (Sandbox Code Playgroud)

转到 master, mater-->rebase on--> 你得到:

Rebase Successful: Rebased master on origin/master
Run Code Online (Sandbox Code Playgroud)

然后用android studio推送。

在此处输入图片说明