I make new branch from master with:
git checkout -b testbranch
I make 20 commits into it.
Now I want to squash those
Checkout the branch for which you would like to squash all the commits into one commit. Lets say its called feature_branch.
git checkout feature_branch
Do a soft reset of your origin/feature_branch with your local master branch (depending on your needs, you can reset with origin/master as well). This will reset all the extra commits in your feature_branch, but without changing any of your file changes locally.
git reset --soft master
Add all of the changes in your git repo directory, to the new commit that is going to be created. And commit the same with a message.
git add -A && git commit -m "commit message goes here"