1

I do the below in my master branch:

git fetch --all

git reset --hard origin/master

Then i create a new branch and switch to the new branch using:

git checkout -b new_branch

I edit and add some files in the new_branch. Then i finally commit.However, when i push the changes, i get the below message:

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.

I have already seen these threads,but still the error persists:

Cannot push to GitHub - keeps saying need merge

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

What else am i missing, i fail to understand? Just to add, i have also deleted my_branch, again updated the master with the latest remote, recreated the new branch, still i encounter the same error, please suggest where i might be going wrong.

fsociety
  • 977
  • 3
  • 12
  • 23

2 Answers2

1

You can force your push with the -f switch. The -f switch forces the push, and will overwrite the branch on the server. Use with caution when working in a team.

git push -f origin new_branch
Donal
  • 31,121
  • 10
  • 63
  • 72
  • there are chances, i might bypass the remote repo commits, will that not be a problem ? – fsociety Oct 02 '17 at 18:10
  • yes, have you performed a pull first? git pull origin master – Donal Oct 02 '17 at 18:12
  • yes, i did a git pull quite a few times, but why does it still say, tip of my current branch is behind remote counterpart, why at all does this message appears ? – fsociety Oct 02 '17 at 18:14
  • 1
    Have a look at the history to see what has happened: gitk HEAD @{u} – Donal Oct 02 '17 at 18:16
  • see here: https://stackoverflow.com/questions/12650261/git-says-local-branch-is-behind-remote-branch-but-its-not – Donal Oct 02 '17 at 18:18
0

Try running:

git pull

If this branch is new, then you can set the upstream with:

git push -u origin new_branch
Thomas5631
  • 244
  • 1
  • 11