It is a veeeery bad idea to modify commits in any way on push. The message is part of the commit ID and thus you will essential make the commit a different commit with a different SHA if you would do such a thing.
Furthermore, a commit does not belong to any branch. A commit can be part of the history of 0, 1 or any other amount of branches. You can only determine to which branches (plural) a commit belongs at the time you are looking. This can change any time basically.
On client side there are hooks that pre-format the commit message or post-process the commit message before / after the editor is invoked when a commit is created, but at this point the commit is not yet present and thus you influence how it will be created, but do not change it which really would be a terrible idea due to several reasons.
What you could do in a server side hook is you could add notes to the commits where you mention the branches to which the commit belongs at push time in a post-receive hook. Notes attached to commits do not change the commits themselves.
git branch --contains <sha-1>to list all local branches that contain a commit. Orgit branch -r --contains <sha-1>to list all remote branches containing a commit. This way you can get the information about which branches a commit has been pushed to without the need of any hooks.