GitBash | origin master - 拒绝(fetch first)| GitHub存储库中没有文件

时间:2017-10-07 11:16:08

标签: git github git-bash git-push git-fetch

我陷入了这段代码。在git fetch之后,我遇到了一堵墙,并且不知道我应该做的下一步是将所有提交的文件都发送到GitHub服务器 - 现在只有一个文件README.md在保存新存储库时自动创建。谢谢你的帮助。

Freeware Sys@DESKTOP-VK97GA5 MINGW64 ~/Desktop/Coding Staff/MustBeDone (master)
$ git status
On branch master
nothing to commit, working tree clean

Freeware Sys@DESKTOP-VK97GA5 MINGW64 ~/Desktop/Coding Staff/MustBeDone (master)
$ git remote add origin https://github.com/adambugaj/Lets-code.git

Freeware Sys@DESKTOP-VK97GA5 MINGW64 ~/Desktop/Coding Staff/MustBeDone (master)
$ git push -u origin master
To https://github.com/adambugaj/Lets-code.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/adambugaj/Lets-code.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.

Freeware Sys@DESKTOP-VK97GA5 MINGW64 ~/Desktop/Coding Staff/MustBeDone (master)
$ git fetch origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/adambugaj/Lets-code
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

GitBash code

2 个答案:

答案 0 :(得分:2)

如果您想保留自述文件,可以将其拉出并重新定位

git pull --rebase origin master

然后推回你的代码

git push origin master

如果您不希望自述文件只是强行推送

git push origin master -f

答案 1 :(得分:1)

看起来您只有默认的README.md文件,该文件随github repo的创建而来。 我会说因为这是你的第一次提交并推送到存储库 继续前进并进行强制推动

git push origin master -f

使用新的存储库还有另一种更简单的方法。 您可以先在任何本地存储库中执行git clone https://github.com/adambugaj/Lets-code.git。然后将所有文件放在该目录中(或者在那里开始编码),然后git push origin master将正常工作。

初始克隆后,您可以根据需要编辑/删除README.md文件。 (但是为你的回购创建一个README.md文件总是好的)