How to Use GitHub Copilot to Write Your First Five Lines of Code
How to Use GitHub Copilot to Write Your First Five Lines of Code
If you're a beginner coder, the thought of writing your first lines of code can be daunting. You might feel overwhelmed by the syntax, the logic, and where to even start. Enter GitHub Copilot, an AI-powered code completion tool that can help you write code faster and with more confidence. In this guide, I'm going to walk you through using GitHub Copilot to write your first five lines of code in 2026.
Time Estimate and Prerequisites
You can finish this in about 30 minutes. Before you start, make sure you have:
- A GitHub account (free)
- Visual Studio Code (VS Code) installed on your machine
- GitHub Copilot extension installed in VS Code (you'll need a subscription)
Step-by-Step Guide to Writing Your First Lines of Code
1. Setting Up GitHub Copilot in VS Code
First, you need to get your environment ready.
- Install VS Code: If you haven't already, download and install Visual Studio Code from here.
- Install GitHub Copilot: Go to the Extensions view in VS Code (you can press
Ctrl + Shift + X), search for "GitHub Copilot," and click "Install".
2. Creating a New Project
- Open VS Code.
- Create a new folder for your project and open it in VS Code.
- Inside the folder, create a new file called
hello.js(or any programming language file you prefer).
3. Writing Your First Line of Code
In the hello.js file, start by typing a comment to describe what you want to do:
// This program prints "Hello, World!" to the console
As you type, GitHub Copilot will suggest completions. You’ll see a greyed-out suggestion appear. To accept it, just hit Tab.
4. Adding More Code
Now, let’s write the code to print "Hello, World!" to the console. You can start typing:
console.log("Hello, World!");
Again, watch for GitHub Copilot's suggestions. If it suggests the line for you, hit Tab to accept.
5. Running Your Code
To run your code, you need to open a terminal in VS Code:
- Go to the top menu and click on
Terminal>New Terminal. - In the terminal, type
node hello.jsand hitEnter. You should see "Hello, World!" printed in the terminal.
6. Expanding Your Code
Now that you’ve written your first line of code, let's add more functionality. You might want to add a simple function. Start typing:
// A function to greet a user
function greet(name) {
GitHub Copilot will likely suggest completing the function. Finish it by accepting the suggestion or typing it yourself.
console.log("Hello, " + name + "!");
}
7. Calling Your Function
Finally, call your function to see it in action:
greet("Alice");
Repeat the process of running the file in the terminal. Now you should see both greetings in your terminal output.
Troubleshooting Common Issues
- Copilot Suggestions Not Appearing: Make sure you are signed in to GitHub and that the Copilot extension is enabled.
- Errors When Running Code: Check your syntax carefully. JavaScript is sensitive to punctuation and spacing.
What's Next?
Now that you’ve successfully written and run your first lines of code, consider exploring more complex features of GitHub Copilot, like generating functions or working with APIs. You can also check out our podcast, Built This Week, where we discuss practical tips for indie hackers and solo founders.
Conclusion
GitHub Copilot can be a fantastic tool for beginners, providing real-time code suggestions and helping you learn as you go. Start with small projects, and over time, you'll find yourself more comfortable writing code.
What We Actually Use
In our experience, we rely on GitHub Copilot for rapid prototyping and learning new programming languages. It's not perfect, but it cuts down the friction of starting from scratch.
Follow Our Building Journey
Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.