Setup and Inline Code Completions
Set up GitHub Copilot, explore inline code completions, and use your first AI-assisted commit with examples.
We'll cover the following...
Writing software isn’t just about solving problems; it’s also about navigating repetition, boilerplate, and constant context-switching. In this lesson, you’ll meet your first true AI pair programmer: GitHub Copilot.
GitHub Copilot helps streamline that process by acting as an AI-powered pair programmer that suggests code in real time so that you can focus on logic, not syntax.
In this lesson, you’ll set up GitHub Copilot in your IDE, explore how it generates useful inline completions, and commit your first AI-assisted snippet to Git. You’ll also see how Copilot handles Python, JavaScript, C++, and Java code, learn to cycle through multiple suggestions, and—if you’re an experienced developer—discover how to tailor Copilot’s behavior to match your style or team standards.
Let’s get started.
Why choose GitHub Copilot?
Before diving into the setup, take a moment to understand what makes Copilot powerful.
GitHub Copilot can autocomplete functions, suggest entire blocks of code, and even write boilerplate for you — all as you type. Whether you’re a beginner or an experienced engineer, Copilot adapts to your patterns and becomes more useful over time.
Imagine typing a function name and watching a working implementation appear beneath it.
Remember: It’s not a trick—it’s Copilot showing up right when needed.
Setting up the GitHub Copilot
Let’s discuss how we can set up the GitHub Copilot in VS Code:
1. Install Copilot in VS Code
If you’re using Visual Studio (VS) Code, follow the steps below:
Launch VS Code.
Go to the “Extensions” sidebar (
Ctrl+Shift+X
orCmd+Shift+X
).Search for “GitHub Copilot.”
Click the “Install” button on the official extension.
Once installed, the Copilot icon will appear in your status bar.
Your task: Try to install the extension. Once done, return to continue.
2. Authenticating with GitHub
Copilot will prompt you to sign in with your GitHub account upon installation. Here’s how:
Click the “Copilot” icon or open any file.
A browser tab opens asking for GitHub authorization.
Click “Authorize GitHub Copilot.”
Once complete, you’ll be redirected, and the IDE will confirm setup.
💡 If the sign-in window doesn’t appear, or you accidentally close it, open the “Command Palette” and run
Copilot: Sign In
to manually authenticate your GitHub account.
Once authenticated, you’re ready to code with AI by your side.
3. Inline completions in action
Let’s see Copilot in action using Python.
Open a .py
file and type the following:
def calculate_area(radius):
Press “Enter” or “Space” after typing your function, and Copilot will instantly suggest a complete code solution.
Within a second, Copilot will suggest:
return 3.14 * radius * radius
Here is the visual representation of how Copilot suggests the code:
What just happened?
Copilot read your function name and parameter, inferred your intent, and wrote a correct implementation for calculating a circle’s area.
To accept the suggestion, press Tab
or Enter
.
Try it now: Type the line, pause, and accept the suggestion.
Copilot across languages
To understand how GitHub Copilot tailors its suggestions based on language, let’s prompt it with the same task—calculating the nth Fibonacci number—in four different languages.
In each case, begin with the starter code, pause, and observe how Copilot completes it. Then, compare the outputs for style, idiomatic use, and clarity.
# TODO: Implement nth Fibonacci numberdef fibonacci(n):pass
Exploring more suggestions
What if you want to see other completions?
Try this example:
def fibonacci(n):
But there’s more. Press:
Alt + ]
(orOption + ]
on Mac) to cycle to the next suggestionAlt + [
(orOption + [
) to go back
You may get:
def fibonacci(n):if n <= 0:return []elif n == 1:return [0]elif n == 2:return [0, 1]fib_sequence = [0, 1]for i in range(2, n):next_value = fib_sequence[i - 1] + fib_sequence[i - 2]fib_sequence.append(next_value)return fib_sequence
Cycle through and choose the one you like. This is where Copilot shines—it thinks like multiple teammates, and you can choose the best voice.
Commit and push
Once GitHub Copilot helps you implement a function—like the Fibonacci example—you’re ready to take it from your editor to your repository. In this section, you’ll learn how to stage, commit, and push AI-assisted code like any human-written code.
Think of this as your AI’s first official contribution to your project.
Step 1: Stage your file
Once your file is saved (e.g., fibonacci.py
, fibonacci.js
, etc.), use the command line to stage it:
git add .
This tells Git: “‘I’m ready to include this file in my next snapshot.”
💡 You can also use
git status
before this step to confirm the file is recognized as changed. Ensure you’ve set up Git locally (git init
and added a remote) and are authenticated to push to your repo.
Step 2: Commit the change
Now create a commit that reflects the work Copilot just helped you with:
git commit -m "Add Fibonacci implementation via Copilot"
This is a clear, readable message that tells your collaborators what was added and acknowledges the use of Copilot. Think of it as documenting both the what and the how.
Use Copilot chat for your commit message
Want to go one step further? Use Copilot chat (Ctrl + I
or Cmd + I
) to craft a polished commit message.
Try asking:
“Write a concise commit message describing this change.”
Copilot chat will analyze your code and propose a well-worded, context-aware message. It might suggest something like:
"Implement recursive Fibonacci function with base case handling"
You can copy and use that message directly, or compare it to your own for style and clarity.
Why it matters: Writing great commit messages is a skill. Copilot can help you learn by example.
Step 3: Push to GitHub
With your changes committed, push them to your remote repository:
git push
Your AI-generated code is now part of your version history—visible to you, your collaborators, and future you.
From Copilot suggestion ➝ to real code ➝ to version control ➝ to the cloud.
Challenge: Merge two sorted lists
You’ve seen GitHub Copilot complete functions, adapt across languages, and even help you write better commit messages. Now it’s your turn to guide Copilot through a real-world algorithmic task requiring precision, performance, and control. Let’s put it to the test.
Problem statement
Write a function:
def merge_sorted(a: list[int], b: list[int]) -> list[int]:
The function should return a new list that:
Merges two already-sorted integer lists passed to it.
Is in ascending order.
Contains unique values.
Runs in
time, where and are the lengths of the two input lists. Does not use
set()
or convert lists to dictionaries.
Expected results
merge_sorted([1, 3, 5], [2, 3, 4])# → [1, 2, 3, 4, 5]merge_sorted([], [-2, -1])# → [-2, -1]merge_sorted([7, 7, 7], [7])# → [7]
These examples test:
Standard merging
Empty list handling
Duplicate removal
How to proceed with the copilot
Start typing:
def merge_sorted(a: list[int], b: list[int]) -> list[int]:
Press “Enter” or “Space” after typing your function.
Copilot will likely suggest the entire merged, sorted code.
Review the suggestion. If wrong, press
Alt + ]
orOption + ]
to cycle through alternatives.When you’re happy with the result, test it locally using the provided main block.
Copy the code you generated with Copilot in VS Code and paste it below to check if it meets the required coding standards.
def merge_sorted(a: list[int], b: list[int]) -> list[int]: # Replace this placeholder return statement with your codereturn []
Great job! You've successfully validated your GitHub Copilot-generated code using the test cases.
Let’s test your knowledge with a quiz on what you have learned so far:
What is one of the primary goals of GitHub Copilot as introduced in this lesson?
To debug large codebases automatically
To replace Git version control
To reduce repetitive coding tasks with real-time code suggestions
To optimize system performance during builds
What’s next?
You’ve set up GitHub Copilot, accepted your first AI-powered suggestion, and committed real code. Next, you’ll take it further with Copilot Chat—where you’ll ask questions about your code, debug issues, and improve solutions through natural, conversational prompts.