This tutorial helps you set up and use GitHub Copilot in VS Code to write, refactor, test, and document code faster.
- A GitHub account with Copilot access
- Visual Studio Code (latest recommended)
- Internet connection
- Open VS Code.
- Go to Extensions (
Cmd+Shift+Xon macOS /Ctrl+Shift+Xon Windows/Linux). - Search for and install:
- GitHub Copilot
- GitHub Copilot Chat
- Sign in to GitHub when prompted.
- Open any project file (for example,
.js,.py, or.ts). - Start typing a function.
- If Copilot suggests ghost text inline, it is active.
- Press:
Tabto accept suggestionEscto dismiss
Use for fast coding while typing:
- Write a clear function name and comment.
- Pause briefly for suggestions.
- Accept full (
Tab) or keep typing to refine.
Example comment:
# Parse a CSV file and return rows grouped by countryUse for explanations, refactors, and generation:
- Open Chat panel (Copilot icon in the sidebar).
- Ask focused prompts such as:
- “Explain this function in plain language.”
- “Refactor this to reduce duplication.”
- “Write unit tests for this file using pytest.”
- Review generated code before applying.
- Select code block.
- Open Copilot Chat.
- Prompt with intent + constraints:
- “Rewrite this to be async, keep the same behavior, and preserve function names.”
- Be specific about:
- language/framework
- desired output format
- constraints (performance, style, compatibility)
- Provide context files or snippets when possible.
- Ask for step-by-step changes for safer refactors.
Good prompt template:
You are helping with a <language> project.
Task: <what to build/change>
Constraints: <rules, versions, style>
Output: <code/tests/explanation>
Try this mini-project:
- Create
calculator.py. - Prompt Copilot:
- “Create a Calculator class with add, subtract, multiply, divide methods and type hints.”
- Prompt Copilot Chat:
- “Generate pytest tests for edge cases, including divide by zero.”
- Prompt Copilot Chat:
- “Refactor for readability without changing behavior.”
You will practice generation, testing, and refactoring in one flow.
- Treat Copilot output as a draft, not final truth.
- Run tests and linters after accepting suggestions.
- Check security-sensitive code carefully (auth, SQL, shell commands).
- Prefer smaller prompts for precise edits.
This workspace now includes a Quarto website scaffold that mimics workflowr-style practice:
- source analysis files in
analysis/ - reproducible execution with
quarto render - publishable static output in
docs/
_quarto.yml: Quarto project and website configurationindex.qmd: Website home pageanalysis/index.qmd: Analysis listing pageanalysis/01-data-check.qmd: Starter Python analysis report
- Install Quarto: https://quarto.org/docs/get-started/
- Create and activate a Python environment.
- Install dependencies:
pip install -r requirements.txt- Render site:
quarto renderRendered pages are written to docs/.
- Run:
quarto render- Commit and push the rendered
docs/directory. - In GitHub repository settings, open Pages and set:
- Source: Deploy from a branch
- Branch:
main - Folder:
/docs
- No suggestions:
- Check GitHub sign-in status in VS Code.
- Ensure Copilot extensions are enabled.
- Reload VS Code window.
- Poor suggestions:
- Add more context and constraints.
- Break tasks into smaller prompts.
- Slow responses:
- Check internet connection and retry.
- Add project-specific prompt recipes to your team docs.
- Use Copilot to scaffold tests first, then implementation.
- Pair Copilot with CI checks for safe, fast iteration.
If you want, I can also generate a short version of this README for workshop handouts, or a team version with coding standards and review checklist.