The following method may work:
git rebase HEAD master
git checkout master
This will rebase your current HEAD changes on top of the master. Then you can switch the branch.
Alternative way is to checkout the branch first:
git checkout master
Then Git should display SHA1 of your detached commits, then you can cherry pick them, e.g.
git cherry-pick YOURSHA1
Or you can also merge the latest one:
git merge YOURSHA1
To see all of your commits from different branches (to make sure you've them), run: git reflog
.