This paper addresses the ultimate goal of code agents that autonomously solve complex tasks. While large-scale language models (LLMs) have made significant progress in code generation, real-world tasks require complete code repositories, not just scripts. Building such repositories from scratch remains a challenging task. GitHub offers a vast collection of open-source repositories that developers frequently reuse as modular components for complex tasks, but existing frameworks such as OpenHands and SWE-Agent struggle to effectively utilize this valuable resource. In this paper, we propose RepoMaster, an autonomous agent framework designed to explore and reuse GitHub repositories to solve complex tasks. RepoMaster constructs function call graphs, module dependency graphs, and hierarchical code trees to identify key components for efficient comprehension, and provides only these key components to LLMs, rather than the entire repository. During autonomous execution, we use exploration tools to incrementally explore relevant components and remove information to optimize contextual utilization. When evaluated on the adjusted MLE-Bench, RepoMaster achieved a 110% relative improvement in valid submissions compared to the most powerful benchmark, OpenHands. On the newly released GitTaskBench, it increased task pass rates from 40.7% to 62.9%, while reducing token usage by 95%.