This approach will potentially discard part of the commit history, but it is easier in case the merge of the old master branch and the current status is tricky, or you simply do not mind losing part of the commit history.
To simply keep things as currently are, without merging, turning the current detached HEAD into the master branch:
detached-head
) that will contain the files in their current status:git checkout -b detached-head
git branch -D master
git branch -M master old-master
git branch -M detached-head master
Credit: adapted from this Medium article by Gary Lai.