Push to a submodule

I have two project that share some code. I want to be able to changes the shared code in either project so I thought about using a submodule for the shared code. But when I change the code from the submodule in one project and then push the changes back to the sub module I get the following error

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags origin master:master
Pushing to C:/Users/stephan/Downloads/Sub
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require ‘git reset --hard’ to match
remote: the work tree to HEAD.
remote: You can set the ‘receive.denyCurrentBranch’ configuration variable
remote: to ‘ignore’ or ‘warn’ in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: To squelch this message and still keep the default behaviour, set
remote: ‘receive.denyCurrentBranch’ configuration variable to ‘refuse’.

Why can I not push back changes to the submodule? Is there a better way of doing this?