It is crucial to identify people at risk for type 2 diabetes mellitus (T2DM) and gestational diabetes mellitus (GDM) to implement preventive interventions in order to address these pandemics. A simple score exclusively based on dietary components, the Dietary-Based Diabetes-Risk Score (DDS) showed a strong inverse association with incident T2DM. The objective was to assess the association between DDS and the risk of GDM in a cohort of Spanish university graduates. The ‘Seguimiento Universidad de Navarra’ project is a prospective and dynamic cohort which included data of 3455 women who notified pregnancies between 1999 and 2012. The diagnosis of GDM is self-reported and further confirmed by physicians. A validated 136-item semi-quantitative FFQ was used to assess pre-gestational dietary habits. The development of the DDS was aimed to quantify the association between the adherence to this a priori dietary score and T2DM incidence. The score exclusively included dietary components (nine food groups with reported inverse associations with T2DM incidence and three food groups which reported direct associations with T2DM). Three categories of adherence to the DDS were assessed: low (11–24), intermediate (25–39) and high (40–60). The upper category showed an independent inverse association with the risk of incident GDM compared with the lowest category (multivariate-adjusted OR 0·48; 95 % CI 0·24, 0·99; P for linear trend: 0·01). Several sensitivity analyses supported the robustness of these results. These results reinforce the importance of pre-gestational dietary habits for reducing GDM and provide a brief tool to practically assess the relevant dietary habits in clinical practice.