How GitHub Copilot fits into my development workflow

I have been using GitHub Copilot for the past six months, and it has quietly become a part of my daily development workflow. It’s a helpful assistant for small, repetitive tasks and a standby teammate I can “talk to” to share thoughts, ask a quick question, or think through a problem when no one else is around. I have used it in Visual Studio Code and JetBrains IDEs, both at my day job and side projects in my spare time. In this post, I will share how I personally use GitHub Copilot and a few hidden features that you might not have come across yet.

This post is not a comprehensive guide to GitHub Copilot’s features or how to use them effectively and responsibly, nor is it a comparison to other AI coding tools (there are numerous other excellent options available). If you’re looking for more official documentation or tutorials, I have included some useful links at the end of this post.

GitHub recently announced a free tier for GitHub Copilot. If you haven’t tried it yet, you can explore some of its features at no cost.

Focus on small, specific tasks

GitHub Copilot is most useful for small, specific tasks and typically less effective when dealing with complex problems that require a broader understanding of business requirements or software architecture. It’s an automation tool that helps you write code faster and reduce repetitive coding tasks, but it can’t replace your skills, experience, and creativity to solve challenging business problems or design innovative solutions.

Personally, I prefer to plan my work and break down a complex feature into smaller, more manageable components instead of using Copilot to generate the entire implementation. I use Copilot to generate boilerplate code, like getters and setters or utility functions, while I take care of the more complicated parts, such as integrating with an external service or implementing a new API endpoint.

Sometimes, asking too many questions or receiving multiple suggestions from Copilot might be overwhelming and lead to loss of concentration.

Get started with new programming languages

GitHub Copilot is a great tool for learning a new programming language. A few months ago, I had to use Go, a language I had never worked with before, to implement some API endpoints. While I spent time learning Go’s syntax and fundamental concepts, Copilot really helped me when I started writing code. I used it to ask coding questions as I wrote, and it often explained concepts or suggested how to organize things correctly using Go best practices.

I also used it as a code reviewer. After finishing my implementation, I asked Copilot to review and optimize parts of the code. I carefully reviewed its suggestions, made a few adjustments, and then passed my solution on to the “real” reviewer. It was a fantastic way to receive quick feedback while learning how to improve my code.

It’s always a good idea to double-check the suggestions you receive from Copilot, especially when you’re learning a new language. For example, you can search for similar questions on Stack Overflow or check the official documentation.

Generate test data for unit tests

Another way I use GitHub Copilot is to automate the generation of test data for unit tests. When I am writing test cases, especially for functions with complex inputs, I usually start with a few example cases to formulate my thoughts and guide Copilot in predicting the expected function’s behavior and autocompleting the remaining cases. This process can save time, especially when you are dealing with repetitive and structured test data.

To improve the quality of the suggestions, I usually add a short comment describing the scenario being tested. This provides Copilot with additional context and leads to more relevant autocompletions. With this approach, I can focus on identifying meaningful test scenarios and edge cases, while Copilot handles the creation of the test data itself.

GitHub Copilot makes suggestions based on the surrounding context. A clean, well-structured suite can lead to better autocompletions. Adding a few initial examples or comments also helps Copilot recognize the pattern you are aiming for.

While I prefer to write the structure of a unit test and let Copilot suggest additional test cases using the real-time autocompletions, there are a few other helpful methods you can try:

  • You can ask GitHub Copilot in the Chat for any missing cases in an existing unit test.
  • You can highlight the code that you want to test and use the /tests slash command in GitHub Copilot Chat to generate unit tests from scratch. Then, you can improve the suggested tests with follow-up prompts. This method is especially useful if you are new to the programming language or testing framework.
  • Alternatively, you can select the code you want to test, right-click in your IDE, and select Copilot: Generate Tests.
Opening one or more existing test files in adjacent tabs in your editor will help Copilot evaluate the testing framework and patterns and will likely lead to more accurate and consistent suggestions.

Document your code

Having well-documented code is essential for maintaining software quality and making future development easier. But let’s be honest, it sometimes feels boring and time-consuming. While GitHub Copilot is primarily used for code generation, I have found it useful for automating documentation. GitHub Copilot can generate concise, clear, and readable descriptions for functions, classes, and modules.

There are multiple ways you can generate documentation. Personally, I typically use autocompletions in the editor, either accepting the auto-generated description when creating a new function or writing the function first and then pressing Enter after the function signature to prompt a suggestion. This method gives me a good starting point, and I usually just refine or expand the description if needed.

Keeping a consistent documentation style in your codebase helps Copilot generate cleaner and more relevant descriptions. For example, if your Python docstrings follow the reStructuredText (reST) format, Copilot will try to match that style automatically.

You can also generate documentation for existing functions using the Generate Docs Smart Action or the /doc slash command in the inline chat. However, I have found these methods to be a bit less flexible, and sometimes the suggestions don’t quite match the style used in the rest of the codebase.

Example of using the /doc command in GitHub Copilot Inline Chat to generate a docstring for a Python function.
Example of using the /doc command in GitHub Copilot Inline Chat to generate a docstring for a Python function.

Document your project and create diagrams

You can use the @workspace participant in the GitHub Copilot Chat along with a short prompt to generate documentation for your entire project. For example, you can ask GitHub Copilot to generate a README file that includes the project’s summary and installation instructions. This works especially well for small projects. For larger codebases, it’s usually just a starting point.

Another great feature I discovered recently is that GitHub Copilot can create diagrams based on the content of your editor. By installing the VS Code Mermaid Chat Extension, you can use the @mermAId chat participant in GitHub Copilot Chat, which provides slash commands for generating sequence and UML diagrams. You can also describe the type of diagram that you need in natural language, and Copilot will generate any diagram supported by Mermaid.

Example of a sequence diagram generated by the GitHub Copilot Mermaid Extension, illustrating how Git works.
Example of a sequence diagram generated by the GitHub Copilot Mermaid Extension, illustrating how Git works.

Resources

You can learn more about GitHub Copilot features in the following links:

You May Also Like