AI Pairing with Copilot
4 learning objectives · 5 key terms · 2 commands · 1 diagrams · 5 quiz questions
AI Pairing with Copilot
Professional PracticeWhat you'll be able to do
- Drive Copilot completions, chat, and CLI with effective context
- Review AI-generated code with appropriate skepticism
- Keep secrets and proprietary code out of AI contexts
- Measure whether AI assistance actually speeds the team up
The idea, in plain language
Muse (completions, chat, CLI, and pull-request summaries) drafts code from context — open files, comments, and repository conventions. It matters because the bottleneck shifts from typing to specifying: well-named functions plus a comment describing intent produce startlingly good drafts, while vague prompts produce confident plausible bugs.
The professional discipline is review parity — AI code gets the same tests, the same reviewers, and extra scrutiny for security-sensitive paths (auth, crypto, queries), because models reproduce vulnerable patterns from training data. Exclude sensitive files from context, know your plan's data handling (business plans retain nothing for training), and measure cycle time rather than assuming acceleration.
Key terms
- Copilot completions
- Ghost-text suggestions inside the editor, driven by surrounding code.
- Copilot Chat
- Conversational asking, explaining, and refactoring against selected code.
- Copilot CLI
- Terminal assistance (gh copilot suggest/explain) for commands and flags.
- Content exclusions
- Repository paths barred from AI context for sensitive code.
- Duplication detection
- Filters blocking suggestions matching public code verbatim.
How it works, step by step
- 1Specify with names and comments
A function named parseRetryAfterMs with a comment stating units and edge cases gets a correct draft; vague names get vague code.
specifybash// parse "Retry-After" header (seconds or HTTP date) to ms; -1 when absent function parseRetryAfter(value) { // <- Tab here for a startlingly good completion }
- 2Chat for understanding and refactors
Select code and ask: explain this, add error handling, convert to async/await — conversational iteration beats re-prompting blindly.
chatbash/explain the selected function /fix the null handling in the selected lines
- 3Review like a junior genius
Assume competence plus overconfidence: run the tests, read every line, and probe security paths (injection, auth, crypto) hardest.
reviewbashnpm test # AI code earns no trust discount # plus: manual review of auth/crypto/query paths
- 4Guard the context
Enable duplication detection, exclude secret-bearing paths from context, and know whether your plan trains on prompts.
guardbash# .github/copilot-exclusions (business/enterprise) secrets/ *.pem
Commands worth memorising
Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.
gh copilot explain "tar -xzvf archive.tar.gz"Extract a gzipped tar archive verbosely...
Terminal help without leaving the shell or trusting memory.
gh copilot suggest "list the five largest files"find . -type f -printf "%s %p\n" | sort -rn | head -5
Review before running — suggested commands get the same skepticism as suggested code.
Workflow diagrams
| Phase | Human does | AI does |
|---|---|---|
| Specify | Names, comments, tests first | Reads context |
| Draft | Prompt precisely | Generates candidates |
| Verify | Reviews, tests, probes security | Explains on demand |
| Integrate | Merges reviewed code | Summarizes the change |
Humans specify and verify; the model drafts in between.
- Specification quality decides output quality.
- Review parity: AI code gets full tests and reviewers.
- Security paths get extra human scrutiny, always.
Worked example
Adding retry timing to a fetcher with AI drafting and human verification.
// fetch with exponential backoff: 3 tries, base 100ms, throws last error async function fetchRetry(url) { // (model drafts the loop; human reviews backoff math + error paths) }
Reviewed helper with tests: backoff timing correct, errors typed, attempts logged.
Where you'll use it
Common mistakes
- Merging unreviewed AI code because it looked idiomatic.
- Vague prompts producing confident, subtly wrong implementations.
- Pasting secrets into prompts or chat contexts.
- Assuming speed without measuring cycle time and defect rates.
Best practices
- Specify with names, comments, and tests before generating.
- Review AI code at full parity — plus extra security scrutiny.
- Exclude sensitive paths from AI context; know plan data handling.
- Enable duplication detection filters.
- Measure team cycle time; keep what accelerates, drop what decorates.
Hands-on exercise
Specify, generate, verify
Ship one AI-assisted helper through full verification.
- Write a function signature plus a comment specifying contract and edge cases.
- Generate the implementation and read every line critically.
- Write tests covering happy path, edges, and failures before merging.
- Probe one security-sensitive aspect (injection, auth, overflow) manually.
- Configure one context exclusion for a secrets-bearing path.
💡 Hint: The comment is the actual work; generation quality tracks specification quality almost linearly.
Done when: A tested, reviewed helper plus one hardened exclusion — and notes on what review caught.
Checkpoint quiz
0 of 5 answered · 0 correct
- Multiple choiceQ1
What most determines AI draft quality?
- Multiple choiceQ2
How should AI-generated code be reviewed?
- True or falseQ3
True or false: secrets and proprietary paths should be excluded from AI context.
- TroubleshootingQ4
AI suggestions keep missing project conventions. What is the highest-leverage fix?
- Multiple choiceQ5
What does gh copilot suggest/explain do?
Module summary
- Copilot drafts from context: completions, chat, CLI, and summaries.
- Specification quality (names, comments, tests) decides output quality.
- Review at full parity, with extra scrutiny on security paths.
- Exclude secrets from context; know plan data handling.
- Measure cycle time — keep acceleration, drop decoration.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.