I want to squash two latest commits with commit messages "first" and "second". First I pull master then I use the command
git rebase -i HEAD~2 master
It shows me both commits in an editor like this:
pick first
pick second
Then I change this editor as:
pick first
squash second
After saving the changes I got this message:
Successfully rebased and updated refs/heads/master.
It did change anything in remote master. To apply these changes I use the git push
command and got the following error:
To https://github.com/aneelatest/GITtest.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/test/GITtest.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Then I again run the git pull
command and it merge origin master and make another commit with this commit message:
Merge branch 'master' of https://github.com/aneelatest/GITtest
After this when I run git push, it squash the two commits into one with message "first". The problem is that in remote master, I have now four commits:
first
second
Merge branch 'master' of https://github.com/test/GITtest
first
Where I want only one commit which is the squashed one with commit message"first". Any ideas where I am doing mistake??