Most existing knowledge tracing models primarily utilize local context information in the sequence of learning interactions, leading to catastrophic forgetting in predicting student performance. Moreover, knowledge tracing models based on skill interactions often overlook the difficulty information of exercise, leading to the models inability to accurately assess the students' knowledge states. However, knowledge tracing models based on exercise interactions face a significant challenge of data sparsity. In order to address the aforementioned issues, we propose a novel knowledge tracing model based on global context information and graph contrastive learning (GCLKT). GCLKT first utilizes exercise interaction sequences to construct a Weighted Exercise Transition Graph (WETG), which transforms the complete sequence structure into a topological graph based on exercise-exercise relationships, providing global context information for each interaction sequence segment. Due to the sparsity of exercise data, two enhanced graphs are obtained by randomly sampling the WETG. Through maximizing the mutual information between node representations and multi-view representations in the enhanced graphs, the model learns enhanced representations of exercises to alleviate the problem of data sparsity. Finally, attention mechanisms are utilized to extract the associative relationships between exercises and skills. Moreover, a subtask is devised to model student knowledge states by predicting the difficulty of exercises as an auxiliary training objective. Experimental results on three datasets demonstrate that the proposed model not only effectively addresses the aforementioned issues but also achieves significant performance improvement compared to existing state-of-the-art baselines.