Table of Contents
Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . xxiii
Chapter 1: Introduction to GitHub Copilot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Understand GitHub Copilot and its core functionality. . . . . . . . . . . . . . . . . . . . . . . . . 2
Explore the AI technology behind GitHub Copilot. . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Learn how GitHub Copilot handles privacy and applies responsible AI. . . . . . . . 23
Recognize the limitations and ethical considerations of GitHub Copilot. . . . . . . 25
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Chapter 2: Setting up GitHub Copilot for your development workflow. . . . . . 33
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Set up your GitHub account and select a Copilot plan. . . . . . . . . . . . . . . . . . . . . . . . 34
Install Copilot in your development environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Configure permissions and personal settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Test Copilot with sample prompts across languages. . . . . . . . . . . . . . . . . . . . . . . . . 50
Troubleshoot installation issues and common errors. . . . . . . . . . . . . . . . . . . . . . . . . 53
Apply best practices for using Copilot effectively. . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Explore Copilots functionality in online and offline modes. . . . . . . . . . . . . . . . . . . 59
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 3: Writing effective prompts for AI-powered coding. . . . . . . . . . 67
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Understand what makes a prompt for AI code generation effective. . . . . . . . . . . 68
Use comment-based, function signature, and docstring prompts. . . . . . . . . . . . . 71
Refine or rewrite prompts to improve suggestion quality . . . . . . . . . . . . . . . . . . . . 74
Apply prompt templates for algorithms, tests, refactoring, and more. . . . . . . . . 77
Customize prompts for specific languages, libraries, and frameworks. . . . . . . . . 81
Identify and fix vague and inefficient prompts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Build an iterative workflow to continuously improve prompt results. . . . . . . . . . 88
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Chapter 4: Enhancing code efficiency with AI assistance. . . . . . . . . . 95
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Apply advanced prompting to guide GitHub Copilot . . . . . . . . . . . . . . . . . . . . . . . . 96
Automate repetitive tasks using AI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Refactor inefficient or legacy code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Implement clean coding practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Improve code readability and structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Evaluate AI suggestions for quality. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Chapter 5: Debugging and troubleshooting code with Copilot. . . . . . . . 139
Practice Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Identify common code issues with GitHub Copilot. . . . . . . . . . . . . . . . . . . . . . . . . . 140
Use Copilot to suggest and apply bug fixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Improve error handling by using AI-assisted recommendations . . . . . . . . . . . . . 150
Optimize code performance through Copilot-driven insights . . . . . . . . . . . . . . . 153
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Chapter 6: Writing and automating tests with GitHub Copilot. . . . . . . . . . 163
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Generate unit tests and integration tests using GitHub Copilot. . . . . . . . . . . . . . 164
Automate test case creation to reduce repetitive coding. . . . . . . . . . . . . . . . . . . . 169
Work with popular testing frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Write clear and structured test prompts for Copilot to follow. . . . . . . . . . . . . . . . 178
Apply best practices to improve the reliability of AI-generated tests. . . . . . . . . 182
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Chapter 7: Using GitHub Copilot for code reviews and collaboration. . . . . . . 191
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Explore Copilots help with code reviews. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Generate refactoring suggestions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Create clear inline documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Use Copilot for alternative implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Collaborate with teammates using AI-enhanced feedback. . . . . . . . . . . . . . . . . . 212
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Chapter 8: Using AI-powered development workflows in real-world scenarios. . . . . 223
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Discover real-world Copilot use cases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Explore AI workflows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Understand the role of AI across industries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Apply practical examples of AI in your projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Reflect on Copilots impact on teams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Chapter 9: Avoiding common pitfalls with GitHub Copilot. . . . . . . . . . . 269
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Spot and fix common Copilot mistakes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Understand why Copilot mistakes happen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Fix and refine AI-generated code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Guide Copilot effectively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Practice real-world examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Chapter 10: Exploring the future of AI in software development. . . . . . 303
Practice files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Explore upcoming AI trends in coding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Understand the evolution of GitHub Copilot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Discover new developer roles in the AI era. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Skills review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Practice tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325