Ai Coding Tools

How to Use GitHub Copilot for Writing Clean Code in 30 Minutes

By BTW Team3 min read

Comparing tools? See the AI tools tested on the show.

In short

A step-by-step tutorial on leveraging GitHub Copilot's features to improve code quality and reduce errors in just half an hour.

If you're like most indie hackers or solo founders, you know that writing clean code can be a daunting task. You want to build quickly but also ensure that your code is maintainable and easy to read. Enter GitHub Copilot, an AI-powered code assistant that can help you write cleaner code faster. In this guide, I'll show you how to leverage Copilot effectively in just 30 minutes.

Prerequisites

Before diving in, make sure you have the following:

  • A GitHub account (Free or Pro)
  • Visual Studio Code installed (free)
  • The GitHub Copilot extension for Visual Studio Code (Free for students, $10/month for individuals)

Step 1: Setting Up GitHub Copilot (5 minutes)

  1. Install Visual Studio Code: If you don’t have it yet, download and install it from here.
  2. Install GitHub Copilot: Open Visual Studio Code, go to Extensions (Ctrl + Shift + X), and search for "GitHub Copilot". Click "Install".
  3. Sign In: Sign into your GitHub account when prompted.

Expected Output: You should see a Copilot icon in your Visual Studio Code toolbar indicating that it’s ready to assist you.

Step 2: Writing Your First Clean Function (10 minutes)

  1. Create a New File: Open a new JavaScript or Python file in Visual Studio Code.
  2. Start Typing a Function: Begin by typing a comment that describes what your function should do. For example, // Function to calculate the sum of an array.
  3. Invoke Copilot: After typing the comment, press Enter. Copilot will suggest code based on your comment.

Expected Output: You should see a clean, functional code snippet that calculates the sum of an array.

What Could Go Wrong

  • Suggestion Doesn't Fit: Sometimes the suggestion may not align with your needs. You can simply type Ctrl + Enter to see more suggestions.
  • Syntax Errors: Always double-check the generated code for syntax errors or logic issues.

Step 3: Refactoring Existing Code (10 minutes)

  1. Paste Your Code: Copy and paste a block of code that you want to improve into your editor.
  2. Add Comments: Write comments explaining the functionality of the code.
  3. Ask Copilot for Improvements: Type a comment like // Refactor this code for better readability and press Enter.

Expected Output: Copilot will propose a refactored version of your code that’s cleaner and more maintainable.

Step 4: Testing the Code (5 minutes)

  1. Run Your Code: Ensure your code runs correctly. If you’re using a language like Python, you can run it directly in the terminal.
  2. Check for Errors: Look out for any runtime errors or unexpected outputs.

Expected Output: Your refactored code should run without issues, confirming that Copilot helped you write clean code.

What's Next?

Now that you’ve got the basics down, consider exploring other features of GitHub Copilot, such as:

  • Generating Tests: Use comments to have Copilot generate unit tests for your functions.
  • Learning Best Practices: Pay attention to the suggestions and learn from them to improve your coding skills.

Conclusion

Using GitHub Copilot can significantly streamline your coding process, allowing you to write clean code in less time. Start with simple functions and gradually incorporate more complex code into your workflow.

Recommendation: If you're just starting, allocate 30 minutes to go through this guide, and you'll see how Copilot can make a difference in your coding practices.

What We Actually Use

In our experience, we use GitHub Copilot primarily for generating boilerplate code and refactoring existing logic. It helps us maintain a clean codebase while saving time on repetitive tasks.

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools
Ai Coding Tools

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them)

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them) In the everevolving landscape of AI coding tools, it's easy to get swept up in the hype. As indie hackers and s

Nov 30, 20263 min read
Ai Coding Tools

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026 In 2026, the landscape for indie hackers and solo founders has evolved significantly, especially with the advent

Nov 26, 20264 min read
Ai Coding Tools

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026 If you’re a developer stuck maintaining legacy code, you know the frustration. It’s like navigating a maze blindfolde

Nov 23, 20264 min read
Ai Coding Tools

10 AI Coding Tools That Will Save You Hours of Debugging in 2026

10 AI Coding Tools That Will Save You Hours of Debugging in 2026 Debugging can feel like a neverending cycle of frustration. Whether you're a solo founder or an indie hacker, spend

Nov 18, 20265 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for MVP Development

10 Common Mistakes When Using AI Coding Tools for MVP Development As a founder in 2026, you’re likely aware that AI coding tools can significantly speed up the MVP development proc

Nov 16, 20264 min read
Ai Coding Tools

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026 As a beginner developer, you’ve probably come across a ton of buzz surrounding AI coding tools. But with all the hyp

Nov 12, 20263 min read