You could do something like this.
# Create temporary branch for your detached head
git branch tmp
# Go to master
git checkout master
# Merge in commits from previously detached head
git merge tmp
# Delete temporary branch
git branch -d tmp
Even simpler would be
git checkout master
git merge HEAD@{1}
but this has the slight danger that if you do make a mistake it can be a little harder to recover the commits made on the detached head.