Ai Coding Tools

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

By BTW Team3 min read

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

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.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

How to Write Your First Code with AI Assistance in 2 Hours

How to Write Your First Code with AI Assistance in 2026 If you're a beginner looking to get into coding, the idea of writing your first piece of code can feel daunting. What if I t

Jul 20, 20264 min read
Ai Coding Tools

10 Mistakes First-Time Coders Make with AI Tools

10 Mistakes FirstTime Coders Make with AI Tools If you're a firsttime coder stepping into the world of AI tools in 2026, you're probably excited but also a bit overwhelmed. We've b

Jul 20, 20264 min read
Ai Coding Tools

How to Build Your First Chatbot Using AI in Just 30 Minutes

How to Build Your First Chatbot Using AI in Just 30 Minutes Building a chatbot can feel like an ambitious project, especially if you're not a coding wizard. But here’s the kicker:

Jul 20, 20264 min read
Ai Coding Tools

10 Mistakes New Programmers Make with AI Coding Assistants

10 Mistakes New Programmers Make with AI Coding Assistants It's 2026, and AI coding assistants have become an integral part of the programming landscape. Despite their potential to

Jul 20, 20264 min read
Ai Coding Tools

How to Master GitHub Copilot in 1 Week

How to Master GitHub Copilot in 1 Week If you’ve been coding for a while, you know the struggle of being stuck on a problem for hours, only to find a simple solution online. Enter

Jul 20, 20264 min read
Ai Coding Tools

The 3 Most Overrated AI Coding Tools in 2026

The 3 Most Overrated AI Coding Tools in 2026 As an indie hacker or solo founder, you’re always on the lookout for tools that can help you code faster and smarter. But in 2026, the

Jul 20, 20263 min read