Paulos3000 Paulos3000 - 7 months ago 38
Git Question

Push to repo failed (Git/GitHub)

I'm trying to push my files to a repo on GitHub, and I'm receiving an error. Could anyone help explain what I'm doing wrong?

An error message is being thrown, but I can't make sense of it (I'm new to Git...)

git push -u origin master

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

Any help would be appreciated.


This is happening because on server you have changes that you do not have on local.

Follow below

  1. Pull from remote git pull origin master
  2. Push into remote. git push origin master

It normally happens when someone has pushed to remote branch after you have taken a pull. Thus, your commit history becomes different from server commit history. In such case, if git would have allowed you to push, the commit history on server (source of truth) would have been altered and also people taking pull from repo would have faced conflicts. Thus, your push is rejected.

However, if you are very very sure that the its a new repo and no one has made any changes to the master remote(as mentioned in comments below) run this git push -f origin master