Github desktop push/pull issue

Whenever I or my teammates sync with the branch we’re in by first commiting our changes, doing a push and then a pull there’s almost always some lines that appear on random places in our code, see the pictures that I’ve provided. What can be done to stop this? Currently we’re just having to go through the code everytime it happens because it stops the code from running completely.

We’re coding in matlab btw.

Hi @profpaulsson,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the How to use Git and GitHub board. No action is needed on your part; you can continue the conversation as normal here.

Cheers!

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:

  1. Created a file named merge-conflicts.md with some basic text using the GitHub UI
  2. Pulled that change to my local machine
  3. Made another change to the merge-conflicts.md file using the GitHub UI
  4. Made different changes to merge-conflicts.md locally and committed them
  5. Executed git push locally

Here is the error message I got when executing from the command line:

$ git push
To https://github.com/lee-dohm/test-repo
 ! [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.