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
git rebase
rewrites history, because the commits were modified. It's not a problem when the said commits haven't been pushed to a remote repository, but here the remote was previously pushed with the commits you rewrote, so it rejected the push.
When you pulled from github, it merged both histories, and applied your squash commit, hence the mess.
Conclusion: when you want to rewrite commits that has already been pushed, you have two options:
git push --force
, which will rewrite history also on the remote, and tell people that you have rewrote history, so they'll see strange things on their next pull.