-1
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/08S/Error.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.
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • https://stackoverflow.com/search?q=%5Bgit%5D+Updates+were+rejected+because+the+remote+contains+work – phd Dec 30 '19 at 20:01

2 Answers2

1

You selected the option on GitHub when creating the remote repository to create it with an existing history (a readme). You want to replace that history, so force-push over it:

git push --force
# git push -f

Or, if you didn’t set the upstream yet:

git push --force --set-upstream origin HEAD
# git push -uf origin HEAD

To avoid this for future existing repos, select the option on GitHub that leaves the new repo on its side empty.

Ry-
  • 218,210
  • 55
  • 464
  • 476
0

It seems the remote repository has some changes that are not in your local repository. So, you have two options.

  1. Integrate the changes in the remote repo into the local repo via git pull command and then push the local changes to the remote repo.

  2. Discard the changes in the remote repo by pushing the local changes to the remote repo via git push --force command.