Skip to main content
This lesson walks through installing and configuring GitHub Copilot in Visual Studio Code, explains key preferences and chat features, and shows how to provide workspace-level instructions that affect Copilot’s behavior. The guide includes examples, configuration snippets, and a small Flask app you can use to test Copilot Chat interactions.

Install GitHub Copilot

  1. Open the Extensions pane in VS Code and search for “GitHub Copilot”.
  2. Click Install.
  3. If this is your first installation, you’ll be prompted to sign into GitHub in your browser to authorize the extension.
Note: the Extensions pane often shows a “Switch to Pre-Release Version” option. The pre-release exposes newer, experimental features but may be less stable. If you want the cutting edge for testing, choose pre-release; otherwise stick with the stable release.
Installing a pre-release version may expose experimental features that can change or break unexpectedly. Use pre-release builds only for testing or in non-critical environments.

Basic Copilot behavior and preferences

Copilot works out-of-the-box after installation, but several preferences let you control how and when suggestions appear. Key options:
  • Inline completions: show inline suggestions while typing. Disable if you prefer fewer distractions during focused editing.
  • Per-language enable/disable: control Copilot per language. By default * is enabled for all languages; you can disable specific languages (e.g., Markdown, plaintext).
  • Completion model: specify a model ID for enterprise/custom usage; leave blank to use the default model.
Common settings can be changed in the Settings UI or edited directly in settings.json. Table: useful Copilot settings at a glance

Example settings.json snippets

General editor settings with a placeholder for Copilot advanced configuration:
Disable inline completions for Markdown and plaintext:
If you add or change workspace-level Copilot instructions, reload the VS Code window (Command/Ctrl+Shift+P → “Developer: Reload Window”) so Copilot picks up the changes.

GitHub Copilot Chat (how it differs from inline completions)

GitHub Copilot Chat is a conversational interface that complements inline suggestions. It excels at tasks that benefit from multi-turn interaction, such as explaining code, fixing tests, generating unit tests, creating feature scaffolding, and performing code reviews. Key Chat features and options:
  • Fix test failure intent: automatically generate fixes for failing tests.
  • Follow-up suggestions: control whether Copilot suggests follow-up messages (options include always, firstOnly, never).
  • Locale override: change the language used by Copilot Chat.
  • Chat scope selection: prompt to select a symbol or file scope for commands like /explain.
  • Terminal chat location: choose where Quick Chat or full Chat appears (Chat view, Quick Chat, or Terminal).
  • Use project templates: allow Copilot to suggest starter code from relevant GitHub repositories during /new.
Enterprise controls: admins can exclude public code from suggestions and restrict whether repository content is used as templates.
A dark-themed settings panel (likely in a code editor) showing GitHub Copilot configuration options like Terminal Chat Location, Use Project Templates, and Enable Code Actions. A hand-shaped cursor is pointing at the "Use Project Templates" option.

Code actions, rename suggestions, and experimental features

Copilot integrates with common editor affordances:
  • Code actions (lightbulb menu): Copilot can surface commands such as “generate documentation” or “generate tests” when applicable.
  • Rename suggestions: Copilot may propose renames to match language and project conventions.
  • Experimental and preview features: items labeled “Preview” or “Experimental” can change over time; examples include “suggest related files”, “temporal context”, and “test generation”. Expect these features to evolve.
A dark-themed settings panel for GitHub Copilot Chat showing a list of experimental options (like suggesting related files, temporal context, and test generation). The screen displays descriptions for each feature and a sidebar with extension categories.

Advanced workspace instructions for Copilot

To influence how Copilot generates and reviews code across a repository, add a repository-level instructions file. These repository instructions are respected by Copilot and Copilot Chat. Create the directory and file from the terminal:
Example contents for .github/copilot/instructions.md:
File-level instructions: include top-of-file comments to control Copilot for a single file. Example Python file header:
After creating or updating these instruction files, reload the VS Code window so Copilot Chat can pick up the changes.

Review tools and security checks

Copilot Chat offers quick code review suggestions for selected regions. It frequently flags obvious vulnerabilities or insecure patterns and provides recommended fixes, making it a useful first-line reviewer. However, do not rely solely on Copilot for security audits—use dedicated security tooling and manual reviews for production code.

How Copilot uses context

Copilot combines local file content, project files, and explicit additions you make to the chat to produce relevant suggestions. Ways to provide context:
  • “Add File to Chat”: includes entire file content for the chat session.
  • Select text + “Add Selection to Chat”: provides targeted context for multi-turn tasks.
  • The chat UI will display which file(s) are in context (e.g., “app.py — current file”).
Useful Copilot Chat commands (typed in the chat input):
  • /new — create a new starter project (can use relevant GitHub repos if enabled).
  • /fixTestFailure and /fix — request fixes for failing tests or specific issues.
  • /explain — ask Copilot to explain code in the selected scope.
  • /startDebugging — request a launch configuration or debugging steps.

Example: Using Copilot with a simple Flask app

This minimal Flask application demonstrates CRUD endpoints and keeps data in memory. Use it to test Copilot Chat prompts like “Generate tests for create_item” or “Create a /ping route”.
After adding app.py to Copilot Chat (using “Add File to Chat”), try prompts such as:
  • “Explain what this file does”
  • “Generate pytest tests for the create_item endpoint”
  • “Review the create_item function for potential security issues”
  • “Create a /ping route that uses ping_db to check connectivity”

Example workflow commands

Create repository-level instructions from the terminal:
Then edit .github/copilot/instructions.md and add your project rules and coding standards. Commit this file to the repository so Copilot will respect these guidelines when editing or generating code.

Summary

  • Install GitHub Copilot from the VS Code Extensions pane and authorize with your GitHub account.
  • Control behavior via the Settings UI or settings.json (inline completions, per-language enable/disable, completion model).
  • Use GitHub Copilot Chat for deeper interactions: explanations, test generation and fixes, code review, and scaffolding.
  • Add .github/copilot/instructions.md for repository-level guidance and use file-level comments for per-file instructions.
  • Populate the chat context (files or selections) to get more accurate and relevant suggestions.

Watch Video