Search code examples
gitgit-mergegit-rebasegit-push

GIT: cannot push to origin/master


enter image description here

This is my situation.

I had pushed version 2.1.6, but it was buggy, so I reverted my filesystem to the 2.1.5 and I then made some changes which I tagged 2.1.7.

Now I cannot push 2.1.7 to origin/master as it says:
Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g.hint: 'git pull ...') before pushing again.

I am very lost now. What should I do, if I just want to discard 2.1.6, and set the origin/master to 2.1.7?


Solution

  • This is your current situation:

    ... ---A------------E master, 2.1.7
           \---B---C---D origin/master
    

    Using git pull --rebase would help you reach this:

    ... ---A---B---C---D---E master, 2.1.7, origin/master
    

    Finally, git push your changes:

    git checkout master
    git pull --rebase
    git push
    

    Or simply using git push --force would help you achieve this:

    ... ---A------------E master, 2.1.7
           \---B---C---D origin/master
    
    git checkout master
    git push --force
    
    ... ---A------------E master, 2.1.7, origin/master