How to push a change in a submodule on Git and do not died trying

Ok, it's a pay in the ass, I'll try to do my best to explain it.

First you do your changes and create a new branch, go to the submodule folder and create a branch called work

git checkout -b work

Once in that branch commit your changes to it, because if not will lose it.

git commit

Then switch again to the master branch

git checkout master

In the submodule folder and run:

git submodule update

Then go to the root project folder and run it again:

git submodule update

Now if you look at your code we losted all our changes, but don't worry because they are on our branch work just do a merge to our master from the work branch.

git merge --no-commit refs/heads/work

And the last steps is push that merge to the server and delete an stage changes that will be automatically created

git push
git reset -q HEAD 

As aditional steps we could delete our temporal branch work

git branch -D work
git push

source

Update: Alternative

Alternatives to git submodule git subtree by @Nicola Paolucci