We study ground state fidelity defined as the overlap between two ground states of the same quantum system obtained for slightly different values of the parameters of its Hamiltonian. We focus on the thermodynamic regime of the XY model and the neighborhood of its critical points. We describe in detail cases when fidelity is dominated by the universal contribution reflecting quantum criticality of the phase transition. We show that proximity to the multicritical point leads to anomalous scaling of fidelity. We also discuss fidelity in a regime characterized by pronounced oscillations resulting from the change of either the system size or the parameters of the Hamiltonian. Moreover, we show when fidelity is dominated by non-universal contributions, study fidelity in the extended Ising model, and illustrate how our results provide additional insight into dynamics of quantum phase transitions. Special attention is put to studies of fidelity from the momentum space perspective. All our main results are obtained analytically. They are in excellent agreement with numerics.