GitHub Copilot best practices: prompts, security, teams
Copilot’s output depends on three things you control: the request you write, the context Copilot can see, and the review process the result goes through. A vague prompt in a repository with no conventions produces generic code that someone then has to fix. A specific prompt, backed by repository instructions and checked by the same reviews and CI as any other change, produces code that fits.
This page collects the practices that matter most, from the individual developer to the organization: prompt engineering, repository instructions, security and privacy, and team governance. Prompts use an invented OrdersPortal codebase. Copilot’s answers vary between runs and models, so the examples show the request and what to check, not a fixed output. Facts were checked against the GitHub Docs source in November 2026.
Topics on this page
Section titled “Topics on this page”| Topic | For |
|---|---|
| Prompt engineering | Getting usable code, tests and explanations on the first or second try. |
| Repository instructions | Giving every request the same project context. |
| Security and privacy | Secrets, private code, public code matches and reviewing AI output. |
| Team governance | Policies, reviews, templates and measuring outcomes. |
Prompt engineering
Section titled “Prompt engineering”GitHub’s own guidance boils down to a few habits. Start general, then get specific: state the goal in one sentence, then list requirements. Give examples of inputs and expected outputs, which pins down behavior better than adjectives. Break complex tasks into smaller ones: “write the parser” then “write the validator”, not “build the import feature”. Avoid ambiguity: name the function, file or library instead of “this” or “it”. Provide relevant context: open or attach the files involved, and paste the exact error. Iterate: refine the request in a follow-up rather than starting over, and start a new conversation when the topic changes so old history does not mislead the model.
The difference shows quickly. A weak request:
Make this better.A request Copilot can act on:
Refactor fetchOrders() in src/api/orders.ts:- Keep the return type Promise<Order[]> and the existing error messages.- Retry failed requests at most 2 times with exponential backoff (200 ms, 400 ms).- Do not retry 4xx responses.- Use async/await, no new dependencies.Then update tests/api/orders.test.ts to cover a retry that succeeds and a 404 that does not retry.For tests, give the behavior, not just the function name:
Write Vitest tests for normalizeCustomerName(input: string): string.Cases: " Ada Lopez " -> "Ada Lopez", "BEN ORTIZ" -> "Ben Ortiz","" -> "", "élodie durand" -> "Élodie Durand" (keep accents).Reusable templates help a team ask consistently:
Task: Implement parseOrderDate(input: string): Date | nullConstraints: no external dependencies; accept ISO 8601 and DD/MM/YYYY; strict validationExamples: "2026-11-05" valid, "05/11/2026" valid, "2026-13-01" null, "5-11-26" nullOutput: the function and 6 unit tests (valid, invalid, leap day 2028-02-29)Before accepting the result, run the same checks you would run on a colleague’s code:
[ ] It compiles and the linters pass[ ] Tests pass locally and in CI, and they test the requirements, not the implementation[ ] Edge cases from the prompt are handled[ ] No new dependencies, secrets or disabled checks slipped inPitfalls:
- Asking for everything at once. Long multi-part requests get partially done. Split them and verify each step.
- Accepting confident explanations. Copilot can explain code it misread. Check claims against the code, especially about concurrency and security.
- Keeping a stale conversation. Earlier wrong answers stay in the context. Start fresh once a thread has gone off track.
Repository instructions
Section titled “Repository instructions”Instead of repeating “we use TypeScript strict mode and Vitest” in every prompt, write it down once. Copilot supports three kinds of repository custom instructions: repository-wide instructions in .github/copilot-instructions.md; path-specific instructions in NAME.instructions.md files under .github/instructions/, which apply to matching files; and agent instructions in AGENTS.md (also CLAUDE.md or GEMINI.md), which some features read. Support for each kind differs between surfaces, so check the support table in the GitHub Docs for the features you use. Personal and organization instructions add to these.
A short, specific .github/copilot-instructions.md for OrdersPortal:
# OrdersPortal
- Stack: TypeScript (strict mode), Node.js 24, Fastify, PostgreSQL via Prisma. Tests: Vitest.- Money is stored as integer cents (number). Never use floating point for amounts.- Validate request bodies with the zod schemas in src/schemas; do not hand-write validation.- Errors: throw AppError from src/errors with a code; never return raw database errors.- Run `npm test` and `npm run lint` before proposing a change as complete.- Do not add dependencies without saying why.Pitfalls:
- Instructions are guidance, not enforcement. Copilot usually follows them but not always; linters, tests and reviews still enforce the rules.
- Long instruction files dilute. Keep them to the conventions that matter and move area-specific rules into path-specific files.
- Keep secrets out. Instruction files are committed and sent as context; never put credentials or internal URLs in them.
Security and privacy
Section titled “Security and privacy”Treat Copilot output like code from a new contributor: useful, fast, and untrusted until reviewed and tested. Models can suggest insecure patterns (string-built SQL, weak hashing, disabled certificate validation) as readily as secure ones, and they can reproduce outdated APIs. The controls below reduce risk; none replaces review.
- Keep secrets out of prompts and files Copilot reads. Do not paste credentials into chat, and keep
.envfiles and keys out of the repository. GitHub secret scanning and push protection catch many leaks before they land. - Content exclusion. On Copilot Business and Enterprise, repository administrators and organization and enterprise owners can exclude paths. Excluded files get no inline suggestions, do not inform suggestions or chat answers, and are skipped by Copilot code review. Support varies by client, and exclusions do not apply to symlinks or repositories on remote filesystems.
- Public code matches. Copilot can generate code that matches public repositories. Depending on your policy, matching suggestions are blocked or shown with a code reference that lists the matching repositories and licenses so you can decide whether to use or attribute it. GitHub reports that matches occur in less than one percent of inline suggestions.
- Data handling. Read the GitHub Copilot Trust Center and your plan’s terms before sending work code. GitHub’s model hosting documentation states that it has agreements with model providers so that data is not used for training, and indexed repositories are not used for model training.
- Agents run with real permissions. An agent that can run terminal commands can run harmful ones. Use manual approvals or sandboxing, and give cloud agents only the repository access they need.
Pitfalls:
- “It came from Copilot” is not a review comment. Reviewers must understand AI-assisted code as well as hand-written code before approving it.
- Exclusion is not access control. Content exclusion limits what Copilot reads; it does not stop people with repository access from reading the files.
- Personal accounts bypass company policy. Using a personal Copilot plan on work code sidesteps the organization’s exclusions and settings; make the policy explicit.
Team governance
Section titled “Team governance”At team and organization level, the goal is to get the productivity benefit while keeping quality and accountability where they were. Start with policy: decide which features, models and agents are enabled, configure content exclusion and the public code policy, and write down acceptable use (which repositories, which data). Then keep the existing safety net in place: branch protection or rulesets, required reviews, status checks, code scanning and secret scanning apply to AI-assisted and agent pull requests exactly as to any other.
CODEOWNERS makes sure sensitive areas get expert review regardless of who, or what, wrote the change:
# .github/CODEOWNERS/src/payments/ @orders-portal/payments-leads/src/auth/ @orders-portal/security/.github/ @orders-portal/platformA pull request template section captures how Copilot was used and what was verified:
## AI assistance- [ ] Copilot (or another assistant) generated part of this change- Areas generated:- Extra validation performed (tests added, manual checks):
## RisksSecurity, performance or data migration considerations:
Measure outcomes rather than activity: review time, change failure rate and escaped defects tell you more than the number of accepted suggestions. Copilot usage metrics for organizations show adoption; pair them with your delivery metrics. Share good and bad examples in a team prompt catalog and keep it next to the code.
Rollout checklist[ ] Policies set: features, models, agents, public code matching[ ] Content exclusion configured for secrets and regulated code[ ] Repository instructions added to the main repositories[ ] Rulesets, required reviews and CI unchanged for AI-assisted pull requests[ ] Pilot team chosen, success metrics agreed, feedback channel openPitfalls:
- Labeling without follow-up. Tagging pull requests as AI-assisted is only useful if someone looks at the data.
- Exempting bots from review. Agent pull requests must not bypass required approvals; GitHub rulesets (in public preview in November 2026) can require an extra approval for pull requests that Copilot opens without a human author.
Choosing between them
Section titled “Choosing between them”| Problem | Start with |
|---|---|
| Answers are generic or use the wrong libraries | Repository instructions |
| One task keeps going wrong | A more specific prompt with examples and verification steps |
| Worry about secrets or regulated code | Content exclusion, secret scanning, acceptable use policy |
| Worry about license exposure | Public code matching policy and code references |
| Quality concerns across the team | Rulesets, CODEOWNERS, required reviews and CI, unchanged for AI output |
Interview questions
Section titled “Interview questions”What makes a good Copilot prompt? A clear goal, explicit constraints (types, libraries, what must not change), concrete examples of inputs and outputs, the relevant files as context, and how to verify the result. Large tasks are split into steps.
Where do project conventions belong: in prompts or in instructions?
In .github/copilot-instructions.md (and path-specific .instructions.md files), so every request gets them. Prompts then carry only what is specific to the task. Enforcement still comes from linters, tests and review.
What does content exclusion do and not do? It stops Copilot from using the excluded files for suggestions, chat context and code review on supported clients. It does not restrict human access, and it has documented gaps such as symlinks and remote filesystems.
How should a team review AI-generated code? Exactly like other code: same rulesets, required reviewers, CODEOWNERS and CI. Reviewers must understand the change; tests should come from requirements, not from the implementation the AI wrote.
Senior scenario: after enabling Copilot, a team’s pull request volume doubles and review quality drops. What do you change? Keep pull requests small and single-purpose, require the AI-assistance section in the template, and make sure CODEOWNERS routes risky areas to experts. Add automated checks that catch common AI mistakes (lint rules, dependency review, secret scanning), consider Copilot code review as a first pass but not as an approver, and track change failure rate and review time to see whether the changes work.
Related pages
Section titled “Related pages”- GitHub Copilot overview: features, surfaces and plans.
- Copilot in VS Code: chat context, agent approvals and shortcuts.
- GitHub repository governance: rulesets, CODEOWNERS and templates.
- Prompt library: ready-made prompts for common development tasks.