Search code examples
gitgithubgit-push

Git push rejected and fetch failed


I am working on my own branch and I have a problem with pushing my last commit.

1) Previously I commited some changes with wrong commit message and updated the commit message by git commit --ammend command.

Now I am able to see this commits on git repository on my branch with previous commited message. (message before ammending)

2) Now I am commited another changes and when I want to push it, I see previous ammended commit is on the push list in addition to my current commits.

But I am not able to push them, git says I need to merge them but when I click merge, it says me :

17:41 Fetch failed: there are still refs under 'refs/remotes/origin/mybr'

17:41 Push rejected: Push was rejected, and update failed with error.

I have no idea where mybr comes from actually. It is not my branch which I am working on.

How can I fix this problem what is wrong ?


Solution

  • Yes, as Tyler points out, the history you're trying to push to the remote doesn't match the remote history of the branch since you rewrote a commit which is now absent in your new history.

    IF this is a feature branch on which you're alone to work, just tell git you do want to push this history even if it doesn't match the current one :

    git push --force <remoteName> <branchName>
    

    If in the other hand you share the branch with people, it would NOT be the way to go. But I guess you would have said so.