Skip to main content
Article
github-copilotai-codingcode-completionide-extensionpair-programmingdeveloper-toolspythonvs-code

Productive Pair Programming with GitHub Copilot

Use GitHub Copilot to accelerate development in your IDE. This guide shows how to get code suggestions, generate functions from comments, create unit tests, and use the integrated chat for complex tasks. Start writing better code, faster.

beginner15 min5 steps
The play
  1. Install and Authenticate
    Install the 'GitHub Copilot' extension from your IDE's marketplace (e.g., VS Code, JetBrains). After installation, you'll be prompted to sign in with your GitHub account that has an active GitHub Copilot subscription. This enables the AI to provide suggestions.
  2. Generate Code from a Comment
    In a Python file, write a comment describing a function you need. Then, move to the next line and wait a moment. GitHub Copilot will read your comment and suggest a full function implementation. Press 'Tab' to accept it.
  3. Use Inline Completion
    Start typing a line of code, like a function call or a variable assignment. GitHub Copilot will offer a greyed-out, single or multi-line suggestion to complete it. This is useful for boilerplate, complex API calls, or repetitive logic.
  4. Generate Unit Tests with Copilot Chat
    Highlight the function you just created. Open the GitHub Copilot Chat panel (usually an icon on the activity bar). Type '/tests' and press enter. Copilot will generate unit tests for the selected code, which you can then insert into a new file.
  5. Explain and Refactor Code
    Highlight a block of code you want to understand or improve. In the Copilot Chat, type '/explain' to get a natural language description. To refactor, you can ask directly, for example: 'refactor this to include error handling for network requests'.
Starter code
import requests

# Welcome to the GitHub Copilot starter file.
# Follow the 'play' steps to complete and test this code.

# STEP 1: Generate a function from this comment.
# Place your cursor on the line below and wait for a suggestion.
#
# function that fetches current Bitcoin price from the CoinDesk API



# STEP 2: Use the generated function.
# Start typing 'if __name__ == "__main__":' below.
# Let GitHub Copilot help you call the function and print the result.



# STEP 3: Highlight your function and use GitHub Copilot Chat.
# Ask '/tests' to generate unit tests for your function.
# Ask '/explain' to get an explanation of how it works.
Productive Pair Programming with GitHub Copilot — Action Pack