GitHub Copilot Cheatsheet
GitHub Copilot
Download free PDFResponsible AI and human oversight
Responsible AI principles
- **Fairness** means assessing unequal outcomes across people and groups. Use representative data, fairness measures and human review; larger datasets alone do not remove bias.
- **Transparency** means explaining the tool's purpose, capabilities, limitations and use of AI. An understandable explanation is useful, but it does not prove an output is correct.
- **Inclusiveness** considers diverse needs and accessibility. **Privacy and security** protect information and prevent unauthorized access throughout the workflow.
- **Reliability and safety** require evaluation under expected and adverse conditions. **Accountability** keeps people responsible for decisions, controls and remediation.
Limitations and validation
- **Generative AI** predicts plausible output from learned patterns and supplied context. Incomplete, biased or outdated information can produce confident mistakes, invented APIs or deprecated syntax.
- **Human review** remains essential for correctness, security, maintainability and licensing concerns. Accepted suggestions and fluent explanations are not evidence of quality.
- **Mathematics and statistics** need independent calculation and domain checks. Verify formulas, assumptions, numerical precision and dataset suitability with executable tools and known results.
- **Overreliance** can hide defects and weaken understanding. Read generated code, run tests and security checks, and keep normal review and release controls.
Features, plans and administration
Interfaces and completions
- **Inline suggestions** propose code as you type, including multiline completions. Meaningful names, nearby code and intent comments help guide the result.
- **Suggestion controls** let you accept, reject or cycle alternatives. Supported editors offer a completions panel and partial acceptance, such as accepting the next word; shortcuts vary by editor.
- **Copilot Chat** supports explanations, code generation and troubleshooting in supported IDEs, on GitHub and in GitHub Mobile. Feature availability differs across clients and plans.
- **Feedback controls** in chat, such as response ratings or Share Feedback, report useful or poor results. Staying in the IDE reduces context switching while preserving the developer's review role.
Subscriptions and access
- **Personal subscriptions** suit individually managed access. Paid personal plans offer monthly or annual billing; working on open source does not automatically make every user eligible for free paid features.
- **Copilot Business** provides centrally assigned seats and organization policies. **Copilot Enterprise** adds enterprise capabilities and governance; check the specific feature rather than assuming every client exposes it.
- **Repository hosting** and Copilot access are separate decisions. Developers can use supported IDE features with code hosted elsewhere; managed identity and enterprise purchasing arrangements depend on the account setup.
- **Access troubleshooting** starts with sign-in, an active entitlement, the enabled extension, supported client features and network connectivity. Inspect policy restrictions, service errors and editor status before changing code.
Shared context and terminal use
- **Knowledge bases** were curated Enterprise documentation collections for grounded answers. They have been replaced by **Copilot Spaces**, which organize shared context; neither term means every repository or file is automatically indexed.
- **Customization** can align suggestions with organizational conventions through supplied examples, instructions and relevant repository context. Repository-adapted models are a distinct customization mechanism, not a correctness guarantee.
- **Pull request assistance** can summarize changes and answer questions about a diff. Check generated summaries against the changeset; a summary does not validate behavior or authorize merging.
- **Terminal assistance** explains and proposes commands. The retired extension used `gh copilot suggest`, `gh copilot explain` and configuration for analytics and execution confirmation; the replacement **Copilot CLI** has a separate command interface. Review commands before execution.
Administration, APIs and metrics
- **Seat-management REST APIs** retrieve subscription or assignment information and add or remove access for selected users or teams. Use authorized credentials and the documented organization or enterprise scope.
- **Audit logs** record administrative and policy events, such as seat changes and content-exclusion changes. Review the organization's Audit log; it is separate from suggestion-acceptance analytics.
- **Usage metrics** describe adoption and activity, including supported completion acceptance, language/editor breakdowns and chat interactions. Available fields depend on the endpoint and reporting scope.
- **Effectiveness** needs context: compare usage trends with developer feedback, task completion and quality checks. Accepted suggestions measure interaction, not automatic proof of secure code, business value or better performance.
Context, architecture and data handling
Suggestion data flow
- **Context capture** selects relevant editor information: cursor position, code around the insertion point, selections and related files. Copilot does not automatically understand an entire repository and all dependencies.
- **Preprocessing** assembles the user's request with available context before model inference. Authorized retrieval or tools may add information when the feature supports them.
- **Fill-in-the-middle (FIM)** considers both the prefix and suffix around a gap. This helps a completion fit surrounding code instead of predicting only from text before the cursor.
- **Response processing** applies relevant filters and policy settings before presentation. Generation and filtering do not imply compilation, test execution, performance benchmarking or retraining on every request.
Retrieval, history and training
- **Training** learns general patterns; **retrieval** supplies relevant material at request time. Grounding can improve relevance without changing model weights.
- **Chat history** supplies conversational context for follow-up requests. Keep related work in one thread and start a fresh conversation when unrelated history would distract from the task.
- **External information** is available only through enabled retrieval or tools. A bare link or file path does not guarantee its contents were fetched; attach relevant text and check reported references.
- **Data handling** separates processing, retention, telemetry and model training. Business and Enterprise customer data is not used to train AI models; personal interaction-data use follows applicable settings and can be opted out of.
Prompt engineering and context crafting
Specify the task clearly
- **A strong prompt** states the goal, language and framework, relevant code, constraints and desired output. Give explicit success criteria rather than asking for vague improvements.
- **Input/output examples** clarify behavior, formats and edge cases. State dependencies, runtime versions and project conventions when they affect the solution.
- **Decomposition** turns a broad request into smaller tasks: explain the existing flow, propose a change, implement it, then validate it. Focused requests are easier to assess and refine.
- **Iteration** uses precise feedback: identify the failing requirement, supply an error or counterexample and request a focused revision. More irrelevant context can obscure the important constraints.
Prompting techniques
- **Zero-shot prompting** gives instructions without worked examples. It can still include detailed context, constraints and an output format.
- **Few-shot prompting** includes a small set of examples demonstrating the desired mapping or style. Show representative tests or naming patterns to encourage consistent output.
- **Role prompting** assigns a useful perspective, such as a security reviewer, and can identify the reader's experience level. Specify the task and evidence as well as the role.
- **Grounded prompting** directs the response to supplied code or documentation. Ask the model to flag missing information and assumptions instead of inventing details.
Context controls and commands
- **Relevant open files** and selected code can improve context. Explicit file attachments or references are more reliable than assuming a file somewhere in the workspace has been read.
- **Chat participants**, such as `@workspace` in clients that expose it, route a request to workspace assistance. **Context references**, such as `#selection` or file references, identify material to use; names differ by editor.
- **Slash commands** express common tasks. Supported clients expose commands such as `/explain`, `/fix` and `/tests`; use the client's command list or `/help` to discover available actions.
- **Command boundaries** matter: `/fix` proposes issue corrections and `/tests` generates test candidates. Visual Studio's `/optimize` requests performance improvements; benchmark any proposed optimization.
Development, refactoring and testing
SDLC support and learning
- **Requirements analysis** can use templates, examples and draft acceptance criteria derived from supplied business requirements. Stakeholders still resolve ambiguity, priorities and conflicts.
- **Design assistance** suggests patterns and trade-offs relevant to the constraints. Developers assess architecture, dependencies, operational needs and compatibility.
- **Implementation assistance** reduces repetitive boilerplate and suggests reusable code. For new languages or unfamiliar codebases, request explanations, small examples and comparisons with familiar constructs.
- **Documentation** can start from generated summaries, comments and API examples. Verify behavior and limitations against code; use synthetic sample data matching the schema and avoid real confidential records.
Refactoring and modernization
- **Refactoring** changes structure while preserving intended behavior. Ask for readable names, smaller functions, lower complexity or improved maintainability, and state the behavior that must stay stable.
- **Inline chat** or a clear intent comment can request a focused code change. Review the diff, public interfaces and error handling before accepting the result.
- **Modernization** may involve language translation, replacement of deprecated APIs or newer patterns. Supply target versions and constraints; verify semantics and dependencies through tests.
- **Performance and security** improvements remain hypotheses until checked. Benchmark algorithms and data structures; review vulnerability fixes with tests, static analysis and dependency scanning.
Test generation and consistency
- **Test prompts** should include the implementation, expected behavior, framework and existing tests. Good context helps identify missing cases and match company conventions.
- **Assertions** check observable outcomes and invariants. Ask for normal inputs, boundaries, invalid inputs, exceptions and failure paths; basic generated tests rarely establish complete coverage.
- **Consistency** improves when examples show fixture structure, naming, setup/teardown and mocking patterns. Few-shot prompts can teach the desired style for unit, integration or other test scaffolds.
- **Test data** should satisfy documented types, ranges and relationships. Generate deliberate edge cases as well as realistic synthetic records; do not confuse plausible values with valid business data.
Test review and execution
- **Review generated tests** for wrong expectations, brittle implementation coupling, missing scenarios and unavailable APIs. A test can repeat the same misunderstanding as the generated implementation.
- **Generation and execution** are separate steps. A chat response containing tests does not establish that they ran; inspect actual runner output when an enabled tool executes them.
- **Coverage reports** reveal unexercised code, but high line coverage does not prove useful assertions or correct behavior. Link tests to requirements and meaningful failure conditions.
- **Integration and end-to-end testing** need realistic dependencies and environments. Performance claims require measured workloads; keep CI checks and human review in the delivery process.
Privacy, exclusions and safeguards
Content exclusion policy
- **Content exclusions** let administrators specify files, folders or repositories that supported Copilot features should ignore. Configure them through Copilot settings rather than invented ignore files or filename suffixes.
- **Managed policy scope** matters: repository administrators govern their repository; organization and enterprise owners govern their applicable users and resources. Personal plan settings do not replace managed exclusion policies.
- **Supported inline completion behavior** blocks suggestions in excluded files and prevents their contents from directly informing suggestions elsewhere. A `.gitignore` file controls Git tracking and is not a Copilot content-exclusion policy.
- **Propagation and diagnosis** can require up to 30 minutes in an already running IDE. Check the applicable seat and policy, path patterns and Copilot status tooltip; reload the editor to refresh settings.
Exclusion limits and sensitive data
- **Exclusion support** varies by feature and client. Verify support for the exact chat mode, agent or tool; exclusions are not a filesystem security boundary or a guarantee that third-party tools cannot read a file.
- **Indirect context** may still reveal semantic information from excluded code, such as types, symbol definitions or project configuration supplied by the IDE.
- **Sensitive information** needs deliberate handling: minimize supplied context, remove secrets and personal data, and use approved access controls. Keep credentials out of prompts and synthetic examples.
- **Retention and training** are separate policy questions. A no-training commitment does not by itself mean no processing or no retention; distinguish prompt content from engagement and diagnostic data.
Public-code and safety filters
- **Public-code matching** checks suggestions for similarity to public code. The block setting can suppress matching suggestions; this differs from detecting duplicate functions inside your own project.
- **Policy administration** can enforce public-code settings centrally through organization or enterprise Copilot policies. Users work within the policies applicable to their assigned subscription.
- **IP safeguards** reduce risk but do not guarantee originality, license compliance or legal protection. Review code provenance and applicable terms rather than treating a filter as a license checker.
- **Safety filters** address harmful or offensive content, including hate speech and explicit sexual content. They are distinct from correctness checks, security scanning and performance validation.