! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/username/repo.git': Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

- 514
- 3
- 16

- 11
- 1
- 3
-
1The answer is right there in the error message... – Thomas Aug 31 '17 at 11:08
-
I'm new to GitHub. @Thomas – Israel Sekhwela Aug 31 '17 at 11:38
3 Answers
Someone else is working with you on the same repository, and they have made some changes that you don't have locally, so first you need to do
git pull origin master
After that solve conflicts if there are any, and at the end you can do
git push origin master

- 514
- 3
- 16
You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again
Pull first, then push to remote because remote has commit(s) that doesn't exist in local.
$ git pull origin master
$ git push origin master

- 22,878
- 9
- 63
- 73
Sounds like you need to pull down work from remote. The smoothest way may be git fetch
followed by git rebase
or as the message suggests git pull
. The former will redo your work on top of the remote work; the latter will create a new commit.
If you're certain you don't care about what's in the remote repository, you can git push -f
, but it's a dangerous operation where your remote will lose old state.
This suggests some other work merged between the last time you grabbed the remote repository and the time you're pushing. Maybe a pull request that you merged or someone else's work?

- 667
- 1
- 4
- 12