I am using a very powerful Unix-like OS under a very nice GUI and typing it on a browser and none of them would exist if lots of people and companies hadn't donated code, time and resources to these projects. I am happy they did and I am willing to share some of what I do to make this whole ecosystem better.
I also share because if I didn't, I would have to maintain my code independently and a great part of it does not give me any product or competitive advantage - it's my cost. When I give them back, I can count they will be part of the whole and they will be maintained by others in case I fail to do it. When I do it, others share the cost of maintaining it, reducing mine.
It's actually pretty dumb to keep everything to yourself.