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

AI Coding Tools: GitHub Copilot vs Codeium - Which One is Worth Your Money?

AI Coding Tools: GitHub Copilot vs Codeium Which One is Worth Your Money? If you’re a developer, you’re likely aware of the growing trend of AI coding assistants that promise to b

Jul 6, 20264 min read
Ai Coding Tools

How to Build an MVP in 1 Week Using AI Coding Tools

How to Build an MVP in 1 Week Using AI Coding Tools (2026) Building an MVP (Minimum Viable Product) in just one week sounds like a stretch, right? But with the right AI coding tool

Jul 6, 20264 min read
Ai Coding Tools

Cursor vs Codeium: Which AI Coding Tool Wins for Productivity in 2026?

Cursor vs Codeium: Which AI Coding Tool Wins for Productivity in 2026? As a solo founder or indie hacker, you know that every second counts when you're coding. Finding the right AI

Jul 6, 20263 min read
Ai Coding Tools

How to Get Productive with AI Coding Tools in Just 2 Hours

How to Get Productive with AI Coding Tools in Just 2 Hours If you're a solo founder or indie hacker, you know the struggle of juggling multiple tasks while trying to code. The drea

Jul 6, 20265 min read
Ai Coding Tools

How to Solve Coding Problems in Under 30 Minutes Using AI Tools

How to Solve Coding Problems in Under 30 Minutes Using AI Tools (2026) As a solo founder or indie hacker, you're likely familiar with the frustration of hitting a coding roadblock.

Jul 6, 20264 min read
Ai Coding Tools

5 Mistakes Beginners Make When Using AI Coding Assistants

5 Mistakes Beginners Make When Using AI Coding Assistants As someone who has dabbled in coding and leveraged AI coding assistants, I can tell you that while these tools can signifi

Jul 6, 20264 min read