Learn GitHub
$ gh ghprofessional.ghcopilot

AI Pairing with Copilot

4 learning objectives · 5 key terms · 2 commands · 1 diagrams · 5 quiz questions

$objectives

AI Pairing with Copilot

Professional Practice

Module 5 of 5 · lesson 22 in this module

What 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
$concept

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

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.
$steps

How it works, step by step

  1. 1
    Specify 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
    }
  2. 2
    Chat 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
  3. 3
    Review like a junior genius

    Assume competence plus overconfidence: run the tests, read every line, and probe security paths (injection, auth, crypto) hardest.

    reviewbash
    npm test  # AI code earns no trust discount
    # plus: manual review of auth/crypto/query paths
  4. 4
    Guard 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

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.

explain a commandbash
gh copilot explain "tar -xzvf archive.tar.gz"
Output
Extract a gzipped tar archive verbosely...

Terminal help without leaving the shell or trusting memory.

suggest a commandbash
gh copilot suggest "list the five largest files"
Output
find . -type f -printf "%s %p\n" | sort -rn | head -5

Review before running — suggested commands get the same skepticism as suggested code.

$diagrams

Workflow diagrams

Diagram 1The AI-assisted loop

Humans specify and verify; the model drafts in between.

Reading the diagram
  1. Specification quality decides output quality.
  2. Review parity: AI code gets full tests and reviewers.
  3. Security paths get extra human scrutiny, always.
$example

Worked example

Adding retry timing to a fetcher with AI drafting and human verification.

specified, drafted, verifiedjavascript
// 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)
}
Output
Reviewed helper with tests: backoff timing correct, errors typed, attempts logged.
1The comment specifies contract, retries, and failure behavior before any code exists.
2The draft arrives; review checks the exponent math and that the final error (not undefined) throws.
3Tests lock attempts, delays (mocked timers), and error identity — AI output now carries proof.
$use cases

Where you'll use it

▸Boilerplate (tests, mappers, glue) drafted from precise specs.
▸Explaining unfamiliar code via chat before modifying it.
▸Terminal command help without context-switching to docs.
▸PR summaries and descriptions drafted, then human-edited.
$mistakes

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

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.
$exercise

Hands-on exercise

Specify, generate, verify

Ship one AI-assisted helper through full verification.

  1. Write a function signature plus a comment specifying contract and edge cases.
  2. Generate the implementation and read every line critically.
  3. Write tests covering happy path, edges, and failures before merging.
  4. Probe one security-sensitive aspect (injection, auth, overflow) manually.
  5. 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.

$quiz

Checkpoint quiz

0 of 5 answered · 0 correct

  1. Multiple choiceQ1

    What most determines AI draft quality?

  2. Multiple choiceQ2

    How should AI-generated code be reviewed?

  3. True or falseQ3

    True or false: secrets and proprietary paths should be excluded from AI context.

  4. TroubleshootingQ4

    AI suggestions keep missing project conventions. What is the highest-leverage fix?

  5. Multiple choiceQ5

    What does gh copilot suggest/explain do?

$summary

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.

Next up: AI-assisted; next is scripting the platform itself — the GitHub API from gh to GraphQL.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

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.