Rechargeable batteries play a pivotal role in the carbon-neutral green environment by electrifying transportation and mitigating the intermittency of renewable energies. Forecasting the degradation of batteries is crucial for the optimal usage of batteries, while predicting battery degradation is not trivial due to diverse working conditions and complex failure mechanisms. To address this challenge, we develop a deep learning model that treats differences in operating conditions as domain shifts and utilizes meta-learning-based and task-driven domain generalization techniques to attack the domain shifts. The model effectiveness is demonstrated on three datasets comprising 203 cells of various operating conditions and chemistries, with improvements in prediction accuracy ranging from 18.1% to 30.0% (23.8% on average). Moreover, the model has gained some generalization capability via learning the correlation between domain gaps in the model and the degradation modes behind various operating conditions. Collectively, our work not only showcases the promise of the high-reliability data-driven model for diverse conditions and chemistries by exploiting domain generalization, but also spotlights the potential interplay between artificial intelligence and domain knowledge.