Search code examples
gitgithubgit-bashgit-pushgit-fetch

GitBash | origin master - rejected (fetch first) | no file in GitHub repository


I'm stuck in this code. After git fetch I met a wall and don't know what a next step should I make to get all my commited files to GitHub server - now there is only one file README.md that was automatically created when saving a new repository. Thanks for help.

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


Solution

  • If you want to keep the readme file you can pull and rebase it

    git pull --rebase origin master
    

    Then push your code back

    git push origin master
    

    If you don't want the readme file just push it forcefully

    git push origin master -f