(This page has no text content)
Praise for Learning GitHub Copilot Learning GitHub Copilot is practical, thoughtful, and grounded in how developers work on code every day. —Andrew Stellman, developer, team lead, instructor, and author Every programmer should understand AI-assisted programming. And GitHub Copilot is the clear leader. Brent’s book is the ultimate guide to mastering this powerful tool. —Tom Taulli, author of AI-Assisted Programming This book is the missing link between using Copilot and truly mastering its potential. It’s an invaluable resource for developers who want to elevate their workflow. —Balaji Dhamodharan, data science leader This book will help to unlock the future of coding. It’s a guide to the tool that simplifies the entire coding process, code explainability, and optimization by offering clear lessons and examples on Github Copilot. Whether you’re new to coding or a seasoned coder, this book will help you increase your productivity. —Aditya Goel, GenAI consultant and assistant vice president at a global bank Learning GitHub Copilot is a comprehensive description of Github Copilot’s features along with usage examples. I found it very informative. —Chhaya Methani, Microsoft
This book expertly balances foundational knowledge with practical applications, making it a must read for anyone eager to explore AI-enhanced software development. —Sundeep Goud Katta, lead software engineer
Learning GitHub Copilot Multiplying Your Coding Productivity Using AI Brent Laster Foreword by Andrew Stellman
Learning GitHub Copilot by Brent Laster Copyright © 2025 Tech Skills Transformation, LLC. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800- 998-9938 or corporate@oreilly.com. Acquisitions Editor: John Devins, Louise Corrigan Development Editor: Michele Cronin Production Editor: Jonathon Owen Copyeditor: Sharon Wilkey Proofreader: Heather Walley Indexer: Potomac Indexing, LLC Cover Designer: Susan Thompson Cover Illustrator: Monica Kamsvaag Interior Designer: David Futato Interior Illustrator: Kate Dullea
July 2025: First Edition Revision History for the First Edition 2025-07-09: First Release See http://oreilly.com/catalog/errata.csp? isbn=9781098164652 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning GitHub Copilot, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-098-16465-2 [LSI]
Dedication To Anne-Marie, coauthor of the amazing book that is our life together.
Foreword I’ve spent a lot of time helping developers learn how to use AI tools as part of their daily work—by mentoring people, running training sessions, and writing about them in books —and I’ve relied on those same tools myself while building real software. One really stands out to me: GitHub Copilot. It’s a game-changer. I use it all the time. I’ve been coding for decades, and like every developer, sometimes I get stuck. Maybe it’s when I’m using a new technology or API, and I’m dreading going through poorly written documentation. Maybe it’s when I’m refactoring a particularly nasty bit of code that everyone on my team has been avoiding. Or maybe I just don’t feel like writing dull boilerplate code that has to get written but is going to cost me a half hour of my life that I’ll never get back. That’s where Copilot can really make a difference. It might give me all the code I need, complete and working. Or it might give me just a starting point—something we’ll iterate on together. Either way, it’s valuable to me, and it almost always gives me enough to get things moving again. But working with Copilot isn’t a one-way street—it comes with responsibility. Copilot can write code that compiles, runs, even passes tests. But if you don’t understand what it gave you, or why it works—or, most importantly, how you got it to produce that result—you’re not really in control of what’s going into your codebase. This book puts you in control. Good developers need to do more than just learn Copilot’s features. We need to learn an effective way to work with AI, one that supports us in what we already do: write code, make decisions, and solve problems alongside other people.
That learning starts with understanding that Copilot isn’t perfect—and it isn’t trying to be perfect. It’s trying to help you move forward by offering suggestions based on the patterns and context in your code. And a lot of the time, it gets satisfyingly close. But like any tool, it works best when you know how to guide it—and when to slow down and double-check what it gave you. And that’s why this book matters. Learning GitHub Copilot is practical, thoughtful, and grounded in how developers work on code every day. Brent Laster has done a masterful job because he doesn’t just list off Copilot’s features; he shows you how to use them when you’re doing real work— when things are messy, nonlinear, and often under a deadline. He starts with Copilot’s built-in strengths, like explaining code and writing tests, and then moves into showing you how it helps with things that trip people up—SQL queries, regular expressions, YAML files, and all the other small (and sometimes not so small!) tasks that eat up time. I appreciate all the examples throughout the book because they reflect the kinds of problems developers face in real life. I think you’ll appreciate them too. Copilot works as an important everyday development tool— not because it promises magic, but because it respects how developers think. This book does the same thing. It assumes you’re thoughtful, capable, and still learning, and it gives you space to make good decisions with the tool instead of just following along. In my own teaching and writing, I’ve seen how quickly developers improve when they get clear, honest guidance— especially when it helps them make better decisions when they’re doing real work. That’s exactly what this book
provides. It’s not hype. It’s not oversimplified. It’s a practical guide to a powerful tool, written for developers who want to stay in control of their code. If you’re new to Copilot, this book is a great place to start. If you’ve been using it for a while, you’ll pick up techniques that make it more effective and easier to trust. And if you’ve been skeptical, that’s healthy. This book meets you where you are, and it’ll show you how to get the most out of the tool without giving up what makes you a good developer. Andrew Stellman Developer, team lead, instructor, and author of Learning Agile, Head First C#, and many other O’Reilly books Brooklyn, New York, April 2025
Preface The winds and the waves are always on the side of the ablest navigators. —Edward Gibbon I’ve been writing code for a very long time now—longer than I care to admit—and I’ve seen the winds and waves of change that have swept across the software development industry multiple times (and written about or trained on many of them). From the internet to CI/CD to containers to cloud, the paradigm shifts have upended the old ways of doing things, and spawned innovation, incredible tools, and turnarounds in our approaches to creating software. And, broadly, those shifts have also generated uncertainty and confusion as individuals tried to understand them and figure out how to adapt and apply their skills.. Now we have generative AI, arguably the biggest wave of change we have encountered in tech, especially for those developing software. Just like the others, it is inspiring massive innovation and driving massive changes. But in some respects, it resembles more of a tsunami where new tools, new models, and new capabilities exhibit tremendous power, all while coders are being swept along and trying to keep our collective heads above water. This book is my attempt to help you surf the wave—at least as far as using the AI powerhouse that is GitHub Copilot. I won’t claim it will answer all your questions, but hopefully it will help you get to a very good comfort level with the tool, let you understand its capabilities (from basic to
advanced topics), and inspire you to make your coding tasks simpler and easier than they’ve ever been before. I’ve been using Copilot in multiple ways for several years: in personal projects, as a former DevOps director piloting it in a corporate R&D organization, as a trainer on Copilot for multiple vendors, as a skeptic, and as an enthusiast. Regarding those last two roles, I wasn’t as impressed with Copilot in its early days as I was with other tools. But over the course of writing this book, developing courses on it, and watching it evolve, it’s become one of the primary tools I use on a regular basis when working in my integrated development environment (IDE) or in GitHub. Copilot has come a long way, even in the last few months. There’s been some impressive progress with features and functionality. I’ve tried to capture as many of those as I could in the book. One of my goals in writing these chapters is to share the benefits and the challenges of using Copilot, and try to help you avoid surprises. So, before you jump in, here’s a few things to be aware of: For the last year or so, GitHub Copilot has changed the appearance and location of at least one dialog or control with nearly every release. I’ve done my best to update screenshots and descriptions as they are at the time of writing. But it’s certain that some will have been moved, changed in appearance, etc. by the time you are reading this. Copilot is now releasing new features on a fairly regular basis. So, over time there will be new features that are not represented in the book. Likewise, some functionality in Copilot is noted as being in preview or experimental as of the time of
writing. Those may have been moved to production by the time you read this or may have been removed if they didn’t make the cut. Copilot runs in many different environments, including multiple IDEs. In each IDE, there can be (and are) differences in integration, appearance, and even functionality. GitHub has historically prioritized Visual Studio Code and the environments that use the same interface (like GitHub Codespaces) to roll out new features and to contain the superset of functionality. For that reason, all screenshots and examples in the book are done with either VS Code or in a Codespace. For those of you using non-VS Code IDEs, some features or functions may have not been implemented by GitHub in that environment. Please consult the Copilot and/or IDE documentation for the latest information. Similarly, IDEs that integrate with Copilot can usually be run on multiple platforms including Windows, Mac, and Linux. Since it’s not practical to cover all the variations in the book, the examples were done on a Mac. So the windows and controls shown may reflect the Mac style. Also keyboard shortcuts will differ among the platforms. To avoid having to list all keyboard shortcuts each time we reference them, we’ve adopted Meta as a notation that means to insert the appropriate shortcut for your platform. All of these things apply across the entire structure of the book, which was written to take you from the What is it basics to the advanced Here’s how you go beyond the core
functionality. Most of the chapters can be read standalone, and you should feel free to skip between chapters as your needs and comfort level dictate. The Structure of This Book Since you’re reading this book, I imagine you’re interested in GitHub Copilot as a potential AI coding assistant or at least looking to learn more about how it and similar coding assistants can be used to help you work more quickly and efficiently. To help with that, an outline of the book’s structure follows. Chapters 1, 2, and 3 guide you through the foundations you need to understand what Copilot is and how to interact with it in its two main modes—code completion and the chat (conversational) interface. Chapter 4 explores advanced ways of interacting with Copilot to do more autonomous editing as well as using Agent mode to drive changes from prompt to finish automatically. This chapter also explores the unique interface of Copilot Vision as well as debugging with Copilot. Chapters 5 and 6 show you how you can leverage Copilot to create rich sets of tests and multiple kinds of documentation to simplify those tasks and give you more time to focus on other coding tasks. Chapter 7 focuses on how you can improve the timeliness and relevance of results from Copilot. Chapter 8 explores how you can use Copilot to handle a number of less common but useful tasks.
Chapter 9 explores Copilot’s chat interface in GitHub and how Copilot can help you understand more about your projects and simplify working with GitHub Issues and pull requests. Finally, Chapter 10 provides information on enhancing Copilot’s functionality through the integration of GitHub Extensions and shows how to build your own. As you start reading, you don’t have to know anything about Copilot to use this book. But I do assume you’re familiar with basic coding skills and have a basic working knowledge of Git and GitHub. The next section explains a bit more about the types of readers who may benefit from the book. Intended Audience This book is for anyone who is trying to learn more about using AI assistants for developing software. Yes, it’s specifically about GitHub Copilot, but many of the examples and flows have parallels in other AI coding tools and environments. To get the most out of this book, you should already have experience coding in an IDE and have a basic knowledge of GitHub. To be clear, this book is not going to teach you how to code, how to use an IDE, or how to use GitHub. But it will help you multiply your productivity in all of those areas through using Copilot. Whether you are a software developer, quality engineer, SRE, or someone who is just looking to understand how an AI assistant like Copilot can benefit them, I believe you’ll find meaningful information and insights. Here are some audiences that I had in mind while writing the book and that I think can benefit from it:
Those who are new (or newish) to AI coding assistants and looking to understand what they are all about and how to best make use of them Those who already understand the concepts and flow of using AI coding assistants and want to understand what GitHub Copilot has to offer Those who want to understand and evaluate GitHub Copilot as a possible tool to use on a wider scale in their organization or business Those who already have some experience with GitHub Copilot and want to take full advantage of its features and functionality Those who are looking to understand how to compensate for some of GitHub Copilot’s shortcomings Those who want to understand the new features of Copilot, such as Agent mode Those who want to create their own GitHub Copilot extensions Those who work with GitHub and want to take advantage of the Copilot integration there If one of these fits your use case, I hope the book will provide you with the value you’re looking for. If you read it and have the opportunity, feedback is always welcome through reviews or interactions at future conferences or training venues. Info about how to ride the wave of Generative AI in coding begins in Chapter 1. Happy surfing!
Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context. TIP This element signifies a tip or suggestion. NOTE This element signifies a general note.
WARNING This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/techupskills/learning-github-copilot. If you have a technical question or a problem using the code examples, please send an email to support@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning GitHub Copilot by Brent Laster (O’Reilly). Copyright 2025 Tech Skills Transformation, LLC, 978-1-098-16465-2.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.
O’Reilly Online Learning NOTE For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in- depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-889-8969 (in the United States or Canada) 707-827-7019 (international or local) 707-829-0104 (fax)
support@oreilly.com https://oreilly.com/about/contact.html We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/learning-github-copilot. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly- media. Watch us on YouTube: https://youtube.com/oreillymedia. Acknowledgments Learning GitHub Copilot marks my fourth published book, alongside many technical guides, reports, articles, and other documents I’ve written over the years. Getting from a proposal to a finished product is an incredible investment of time and energy not only from the author, but from a team of people to bring things to production. I am incredibly grateful to the following group of people who contributed their time and energy to bring this project to the point where you can read it and hopefully get value from it. First, many thanks to John Devins, my acquisitions editor at O’Reilly who believed in, and advocated for, this book—as he did on my behalf for so many other projects. John, I hope you’re enjoying a well-deserved retirement! And thanks to Louise Corrigan for picking up from John to continue the effort. Over my time working with O’Reilly, I have truly come to respect and appreciate the role of acquisition
Comments 0
Loading comments...
Reply to Comment
Edit Comment