Migraine and headache frequently co-occur with type 2 diabetes (T2D), suggesting a shared aetiology between the two conditions. We used genome-wide association study (GWAS) data to investigate the genetic overlap and causal relationship between migraine and headache with T2D. Using linkage disequilibrium score regression (LDSC), we found a significant genetic correlation between migraine and T2D ( = 0.06, = 1.37 × 10) and between headache and T2D ( = 0.07, = 3.0 × 10). Using pairwise GWAS (GWAS-PW) analysis, we identified 11 pleiotropic regions between migraine and T2D and 5 pleiotropic regions between headache and T2D. Cross-trait SNP meta-analysis identified 23 novel SNP loci ( < 5 × 10) associated with migraine and T2D, and three novel SNP loci associated with headache and T2D. Cross-trait gene-based overlap analysis identified 33 genes significantly associated ( < 3.85 × 10) with migraine and T2D, and 11 genes associated with headache and T2D, with 7 genes (, , , , , , and ) common between them. There was also a significant overlap of genes nominally associated ( < 0.05) with both migraine and T2D ( = 2.83 × 10) and headache and T2D ( = 4.08 × 10). Mendelian randomisation (MR) analyses did not provide consistent evidence for a causal relationship between migraine and T2D. However, we found headache was causally associated (inverse-variance weighted, OR = 0.90, = 7 × 10) with T2D. Our findings robustly confirm the comorbidity of migraine and headache with T2D, with shared genetically controlled biological mechanisms contributing to their co-occurrence, and evidence for a causal relationship between headache and T2D.