(Disclaimer: I have fired people, and I have had two people transferred off my team onto other teams, and both of them have left the company, but I don't count those as attrition under me.)
But if I had to pick something as a thing that I do to make sure my teams are happy and want to stay, it's this: I care deeply about the people who work for me. I'm a people-first leader. I firmly and strongly believe that unhappy people do shitty work, and happy people do good work. I believe that you don't get what you don't ask for (eg, raises, promotions, cool projects), and I also believe that most people won't ask for those things... so I pro-actively ask for them. Our 1:1s are their time to talk about whatever they want to talk about. It's not my time to pontificate. But if they don't have anything to talk about, I'll ask them questions! Things like: where do you see yourself in 5 years? Are you happy with the project you're working on? Are there cool projects that you want to work on? Is there a piece of technology that you haven't used that you would like to learn?
And then once I get those answers, I work with them to achieve those goals. If they want to be a manager in 5 years, then we work on that. If they love the project they're on, then I get them more involved. If they want to work on Project X, then I figure out a way for them to transition off what they're doing now and move on to the other thing.
I also spend a lot of time getting to know them as people. I know their partner's and kids' names, their hobbies, where they go on vacation. I frequently ask questions about those, like, "Did [partner's name] get that promotion?" or "Are you looking forward to your next trip to Disney World?" or "Has [kid's name] seen the movie The Mitchells & The Machines?" and so on.
I'm transparent and honest. I make it clear that I support them as much as I possibly can, and that I would rather they be successful and happy than successful and miserable. One of my guys came to me about three months ago and said, "A recruiter from Stripe reached out to me about a role there. Why shouldn't I apply there?" and I just shrugged and said, "You should. You should always have an idea of what you're worth on the market, and if you think that's a better fit for you than here, I support you." And he applied and he got an offer and it was a little more than he was making here, but he declined because he felt like he'd be a cog in the machine at Stripe versus a valued member of my team. On the flip side, the offer clarified some ideas that he had in his mind about where he wanted to take his career, and so for the past few months we've been talking in our 1:1s about how to shift his career into a different direction, and he's been taking advantage of some opportunities that have come up.
(NOTE: Despite the above scenario, I would never ever suggest to your boss that you are looking elsewhere, no matter how good your relationship is with your boss. It puts us in a very difficult position regarding certain decisions around pay raises and bonuses and promotions and hiring and so on. I did give this feedback to this engineer.)
So if I had to claim credit for anything, it's just that. The soft skill of treating people like people, trusting them to do their jobs well, and giving them the space to make mistakes, learn, and grow along with me. After all, I don't know what the hell I'm doing either. :)
(I really do think I got lucky with a team of rockstar engineers.)