How to Use GitHub Copilot for Beginners: Write Your First Function in 10 Minutes
How to Use GitHub Copilot for Beginners: Write Your First Function in 10 Minutes
If you're a beginner in coding, the thought of writing functions from scratch can feel overwhelming. Enter GitHub Copilot, an AI-powered coding assistant that can help you write code faster and with more confidence. But how do you actually use it? In this guide, we’ll walk you through writing your first function with GitHub Copilot in just 10 minutes.
Prerequisites: What You Need
Before diving in, make sure you have the following:
- A GitHub Account: You can sign up for free at GitHub.com.
- Visual Studio Code (VS Code): Download and install it if you don’t have it already.
- GitHub Copilot Subscription: As of May 2026, GitHub Copilot costs $10/month after a free trial. You can cancel anytime.
Step-by-Step: Writing Your First Function
Step 1: Install GitHub Copilot
- Open VS Code.
- Go to the Extensions view by clicking on the Extensions icon in the sidebar or pressing
Ctrl+Shift+X. - Search for "GitHub Copilot" and click on "Install".
- Follow the prompts to authenticate with your GitHub account.
Step 2: Create a New File
- Create a new file in VS Code with a
.jsextension (for JavaScript) or any other language you prefer. - Start typing a comment to describe the function you want to create. For example:
// Function to calculate the square of a number
Step 3: Let Copilot Suggest Code
- After typing the comment, hit
Enter. - GitHub Copilot will suggest a code snippet. It might look like this:
function square(num) { return num * num; } - If you like the suggestion, hit
Tabto accept it. If not, you can scroll through other suggestions by pressingCtrl + ]orCtrl + [.
Step 4: Test Your Function
- Below your function, call it with a test value:
console.log(square(5)); // Should print 25 - Save your file and run it using Node.js or your preferred runtime.
Expected Output
If everything goes smoothly, running your file should print 25 in the console, confirming that your function works!
Troubleshooting Common Issues
- No Suggestions: If Copilot doesn’t suggest anything, ensure your comments are clear and descriptive. Sometimes, more context helps.
- Incorrect Code: Review the suggested code carefully. AI can make mistakes, so always validate the outputs.
What's Next?
Now that you've successfully written your first function, consider exploring more complex functions or even other languages. GitHub Copilot can assist with:
- Writing tests for your functions.
- Creating entire classes or modules.
- Learning new programming concepts through code suggestions.
Limitations of GitHub Copilot
While GitHub Copilot is incredibly useful, it does have its limitations:
- Context Awareness: It might not fully understand your project's context, leading to irrelevant suggestions.
- Learning Curve: Beginners might still need to learn basic coding principles to make the most of Copilot's suggestions.
- Cost: The $10/month fee might be a barrier for some indie hackers.
Conclusion: Start Here
If you're just starting with coding, GitHub Copilot can significantly reduce the learning curve and speed up your development process. Follow the steps above, and you'll be writing functions in no time. Don't forget to keep experimenting with different types of functions and coding languages!
What We Actually Use
In our experience, we use GitHub Copilot mainly for rapid prototyping and learning new languages. It’s not a replacement for understanding code but a fantastic tool to speed up our workflow.
Follow Our Building Journey
Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.