为什么我仍然无法将我的代码推送到github?

时间:2019-07-25 04:29:35

标签: git github version-control

我是git新手,发生了以下情况: 我一直在从事一个项目,创建一个分支并愉快地提交并将代码推送到github,没有问题,然后在某个时候,我更改了github名称,即我用git remote set-url origin NEWURL更新了我的遥控器remote -v使用git push,但仍然失败。我尝试git rebase config_options/config_options之后说│fatal: Needed a single revision,但仍然无法git push,Ineed还可以做什么?

$ git push To https://github.com/stdcerr/scaper.git ! 
[rejected]                 master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/stdcerr/scaper.git' 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. Check out this branch and 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,但我只得到Already up-to-date. 我尝试了git pull --rebase,并得到了以下内容:

$ git pull --rebase
Current branch config_options is up to date.
ron@regDesktopHome:~/src/scaper$ git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 353 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/stdcerr/scaper.git
   3747bbb..06a769e  config_options -> config_options
    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/stdcerr/scaper.git'
    hint: Updates were rejected because a pushed branch tip is behind its remote
    hint: counterpart. Check out this branch and 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

1 个答案:

答案 0 :(得分:1)

当您在其中创建带有提交的新存储库(用于初始README或LICENSE文件)而不是创建一个 empty 存储库(没有提交且没有文件)时,通常会看到这种情况

如果创建一个空的存储库,则可以毫无问题地进行推送。

如果没有,则首先需要git pull --rebase,然后是git push --force