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

10 Common Mistakes When Using AI Coding Tools for Beginners

10 Common Mistakes When Using AI Coding Tools for Beginners As a beginner in coding, diving into AI coding tools can feel like a doubleedged sword. On one hand, these tools promise

Oct 8, 20264 min read
Ai Coding Tools

5 Common Misconceptions About AI Coding Tools and Why They Hold You Back

5 Common Misconceptions About AI Coding Tools and Why They Hold You Back As a solo founder or indie hacker, you might be considering leveraging AI coding tools to boost your produc

Oct 7, 20264 min read
Ai Coding Tools

5 Common Misconceptions About AI Coding Tools That Will Hurt Your Learning

5 Common Misconceptions About AI Coding Tools That Will Hurt Your Learning As a beginner in coding, diving into the world of AI coding tools can feel like stepping into a futuristi

Oct 6, 20263 min read
Ai Coding Tools

10 AI Coding Tools Beginners Overlook in 2026

10 AI Coding Tools Beginners Overlook in 2026 As a beginner in coding, diving into the vast ocean of AI tools can feel overwhelming. While flashy tools often grab the spotlight, ma

Oct 6, 20265 min read
Ai Coding Tools

5 Common Misconceptions About AI Coding Tools That Beginners Believe

5 Common Misconceptions About AI Coding Tools That Beginners Believe As a solo founder or indie hacker, diving into the world of AI coding tools can feel overwhelming, especially i

Oct 5, 20263 min read
Ai Coding Tools

5 Mistakes Every Beginner Makes When Using AI Coding Tools

5 Mistakes Every Beginner Makes When Using AI Coding Tools As a solo founder or indie hacker diving into the world of AI coding tools, it’s easy to get swept up in the excitement o

Oct 4, 20264 min read