Those are merge conflict markers. Git leaves them in files when two commits make different changes to overlapping areas in a file. GitHub prevents you from pushing when there are changes remotely that you do not have on the branch you’re pushing from. For example, in my test repository, I did the following:
Created a file named
merge-conflicts.md with some basic text using the GitHub UI
- Pulled that change to my local machine
Made another change to the
merge-conflicts.md file using the GitHub UI
Made different changes to
merge-conflicts.md locally and committed them
git push locally
Here is the error message I got when executing from the command line:
$ git push
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/lee-dohm/test-repo'
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.
And this is the error in GitHub Desktop:
If I pull first in GitHub Desktop, I get this dialog specifically warning me that there are merge conflicts:
And the merge conflict is helpfully displayed:
So the solution is to always pull, resolve any merge conflicts, commit those changes and then push.