Unfortunately, Erdoğan realized that and very carefully removed secular officers from the senior ranks, largely through retirement. In their place, he promoted Islamists who owed their allegiance to him and would never challenge his grip on power, as long as he took care of his military allies. The recent failed coup--if it actually was a coup--illustrates how impotent secular elements in the military have become.
An equally important question: who lost the TGS?
Interesting tidbit - every spring, when the promotion list came out, the Turkish GO/FO would gather to discuss the names and remove any considered ‘too Islamist’. That process ceased around 2008, when Erdogan took a hard line with the military, and it’s been downhill ever since.