This happens when there have been changes to both your local branch and the remote branch and the reason why you are not allowed to push your changes to the remote branch is because the remote changes could get overwritten by your local changes if you were to just push the changes.
One way to solve this is to use a feature in git called rebase
. What it does is that it replays your changes on top of the remote branch, to ensure that your branch is up-to-date and then builds on the remote branch.
You should be able to solve this problem by updating your local branch by running this command: git pull --rebase
. This will pull the remote changes and then replay your local changes on top of those.
You can read more on git-rebase here: https://git-scm.com/book/en/v2/Git-Branching-Rebasing
If, however, you really want to overwrite the remote branch, there is also a --force
option to git push
. I would not recommend it unless you really know what you are doing. More information on what options are available for pushing can be found here: https://git-scm.com/docs/git-push