Code search plays a role in bridging code and query. However, recent code search studies mainly rely on affinity-matrix-based cross-modal attention to learn the word alignments between code and query, which may lead to incorrect alignments. In this paper, we propose a Global Alignment Learning Model (GALM) to learn global alignments and demonstrate that better-learned correct alignments can significantly improve code search performance. Specifically, GALM characterizes the query and code embedding into an alignment graph to enhance the feature representation and further learns global alignments by a dense graph convolutional network. To evaluate the performance of GALM, we compared it with several baseline models on two popular datasets. The results demonstrate that GALM outperforms the best baseline models by 9.8\% and 6.8\% with the Top@1 accuracy of 0.601 and 0.671 on two datasets, respectively.