4 is the number of commits you want to squash
git rebase -i origin/master~4 branch_name
This will open your edit, replace the pick
with squash
on the commits you want to squash into the main commit.
The editor will open again and you need to comment out all commit messages that you don't want.
git push -f git push origin +branch_name