git: "Updates were rejected because the tip of your current branch is behind.." but how to see differences?

Viewed 69261

I just finished working on a piece of code. Wanted to push and got the already famous:

hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.

Now I've seen this question posted several times here, e.g.

Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g

Updates were rejected because the tip of your current branch is behind

According to the specific case, the solution is either to

  • git pull, so the remote changes are merged on to my local work, OR
  • git push -f, a force push to update the remote (origin) branch.

Now, it has been a while I haven't worked on this branch. I don't necessarily want to merge the remote changes onto my current work! Nor do I know if I can safely force the update on the origin branch...

How can I just see the differences and decide which is best for my case?

4 Answers

I had this happen to me recently when I created a new branch with git checkout -b feature/abc, committed some changes, and then tried git push --set-upstream origin feature/abc it to create a pull request for review. The error occurred because the remote branch already existed when I thought I was defining the branch locally. Deleting the remote branch resolved the issue and my push succeeded.

I wanted to add a scenario that happened to me recently where this error shows up seemingly out of nowhere, even when you do everything right. The cause wasn't obvious but finally seemed to be the change in default push behavior since git version 2.0. I was collaborating with someone using git version 1.8 and I had version 2.x. So although we were both doing git push, different types of push were happening. For us, the problem resolved once we changed the default push behavior by simply running this command on git version 1.8 computer-

git config --global push.default simple

This changes the push.default of git version >=1.7 to same as for version 2.0 onwards. For lower versions of git, you might need another default behavior. We both are new to git so correct me if I am wrong but this did made our "Updates were rejected..." error go away.

Also, if there is a better venue for this answer, let me know and I'll be happy to move it to somewhere else.

Related