I feel like this comes up with me in programming too! Like if I write some really beautiful function as part of solving a problem, I will be a lot sadder if it doesn't make it in, sometimes to my detriment. Similar energy to "cattle not pets".
Probably the most important lesson my C mentor ever told me: "Never be afraid to delete code, no matter how nice you think it is." It still hasn't fully landed with me, and I can relate to what you wrote. But I am trying to.