git checkout feature
git rebase master
....
First, rewinding head to replay your work on top of it...
Applying: added comment
Applying: one more comment
git checkout master
git merge feature
...
Updating f45a1c3..ea54235
Fast-forward
git checkout feature
git rebase -i HEAD~2
...
pick f45a1c3 added comment
squash ea54235 fixed comment
# Rebase c2d5714..ea54235 onto c2d5714
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
git push --delete origin remote_branch_name
git rebase -i HEAD~2
git push -u origin remote_branch_name
In case with existing remote branch first remove remote branch, squash local branch and push new remote branch.