Yeah, it is a chicken and egg problem, you just have to choose who’d should be the first
In fact, what’s under .teamcity is a Maven project. So if we think of it as if it is not a configuration, but an application code, then we can just configure a build configuration that will invoke the Maven goals and run tests and then merge the changes from the branch into master.
Maybe it is worth using a dedicated repository for the .teamcity configs even.