无法推送到 github 中的远程存储库

Can't push to remote repository in github

我是 github 的新手,所以为了测试,我一直在修改我的 .gitconfig 文件(添加一些有用的别名等)并将其推送到我的 "Config Files" 存储库在 github.

我有两台电脑,一台台式机和一台笔记本电脑。当我在桌面上修改本地文件,提交并推送到远程存储库时,它工作正常。

但是,当我尝试在笔记本电脑上执行相同操作时,出现此错误。

     ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/User/Config-Files.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.

此外,如果我尝试像消息建议的那样先拉,我会收到此错误消息:

$ git pull origin master
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), 355 bytes | 8.00 KiB/s, done.
From https://github.com/User/Config-Files
 * branch            master     -> FETCH_HEAD
   627ab06..b327e2b  master     -> origin/master
fatal: refusing to merge unrelated histories

远程存储库只有 .gitconfig 文件,与我尝试从笔记本电脑推送的文件相同,为什么会出现此错误?

答案在你的终端里,它告诉你先获取。

您已经从台式机推送到 master,而您在笔记本电脑上的提交落后了。所以你必须获取,合并,然后你就可以从你的笔记本电脑上推送..

这是一种不好的做法,但总是可以强制执行...(--force),但随后在您的桌面上所做的任何更改都将消失。