For test/production environments I have a separate config file that is not committed to the repository.
Continuous integration tools like GitLab CI, Drone CI, and I believe Travis CI have support for application secrets so that can be used for automated deployment. Alternatively, these config files can live on the servers.
Some automation tools like Ansible have the ability to encrypt the secrets so they can be pushed to the repository, but I've never done it. Docker swarm also has support for defining secrets, and I'm sure Kubernetes does too.