While the user push code to a master branch, the message shows the user doesn’t have permission to push the code to the protected master branch.
Is there a way to know who protected the master branch?
And is there a way to protect a branch by API?
the default branch (master, main, or let’s just say the HEAD reference) is protected by default in GitLab by GitLab itsself on creation of the repository or the first push to an empty repository. See Protected Branches
The API is described here: API Ressources > Protected branches API > Protect repository branches
If you host your own gitlab instance you could find out who personally protected a branch if you look into the logs who did a POST to
I have not seen this information avaliable in the WEB-UI yet.