I rebased changes from a remote repo upstream master
into my local dev
branch and then tried pushing the changes to my repo using these commands:
git pull --rebase upstream master
git push origin dev
but the later command resulted into that error:
error: failed to push some refs to 'https://github.com/m-adil/some_repo.git'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
This is what that I'm facing for the third time but didn't come across with a perfect solution yet. Doing git pull ...
as suggested in second last line of error, results in producing all the conflicts again that ruins the recent git pull --rebase ...
. In such cases git reset --hard HEAD@{1}
remediates but what is the best approach in this case to push your changes?
I explored this and found several similar questions here but with some minute distinctions that don't clarify this issue to me. Most of the selected answers suggests to do git push --force origin my_branch
but it has cons as well and one can lose his changes in remote so this can't be suggested.
The best thing I came to know yet is to create & checkout to a new branch which is better than many other answers/solutions. But this is more like a trick to escape from this issues rather than a right approach to deal with that situation. So can any body please clarify by sharing the right approach in this case?