I only understood as far as you CAN create a module.
As for the rest,
Why are you doing all this for testing? First you make your module work in an application as a native module, only then test it’s installation on a clean system with composer. Why are you doing this every time?
As for easiness of deployment, currently few modules can boast a zero configuration. Some of it needs to be done anyway. Are you talking about this?
I made native module.I’m able to change it to an extension and install it to clean system with composer also.
My real problem occurs when I want update module,I have to convert extension to native module again,do changes and test in dev env,then convert it to extension again.
because everything in vendor directory ignored by git.
I think you need automate module => ext conversion, for which you need to write some shell or php script that should handle the routine tasks for you.
Then you should automate deployment to clean yii installation and check if it works.
Git subtree might help you to sync folders, but if there are other changes (i.e. modifying the code) i’d advise against it.
Also, I do not understand why can’t you develop your extension already in vendor directory, as it would be on any project? This should remove the need to convert module to extension and vice versa.
Why subtree? Just use development version of the package. Composer should get your module from repository so you have .git in your vendor/arash26/mymodule and can use git from the dir.