|
| 1 | +--- |
| 2 | +title: Best practices for using GitHub Copilot |
| 3 | +intro: 'Learn how to get the most out of {% data variables.product.prodname_copilot_short %}.' |
| 4 | +topics: |
| 5 | + - Copilot |
| 6 | +versions: |
| 7 | + feature: copilot |
| 8 | +shortTitle: Best practices |
| 9 | +--- |
| 10 | + |
| 11 | +## Understand {% data variables.product.prodname_copilot_short %}'s strengths and weaknesses |
| 12 | + |
| 13 | +{% data variables.product.prodname_copilot %} is an AI coding assistant that helps you write code faster and with less effort, allowing you to focus more energy on problem solving and collaboration. Before you start working with {% data variables.product.prodname_copilot_short %}, it's important to understand when you should and shouldn't use it. |
| 14 | + |
| 15 | +**Some of the things {% data variables.product.prodname_copilot_short %} does best include**: |
| 16 | + |
| 17 | +* Writing tests and repetitive code |
| 18 | +* Debugging and correcting syntax |
| 19 | +* Explaining and commenting code |
| 20 | +* Generating regular expressions |
| 21 | + |
| 22 | +**{% data variables.product.prodname_copilot_short %} is not designed to**: |
| 23 | + |
| 24 | +* Respond to prompts unrelated to coding and technology |
| 25 | +* Replace your expertise and skills. Remember that you are in charge, and {% data variables.product.prodname_copilot_short %} is a powerful tool at your service. |
| 26 | + |
| 27 | +## Choose the right {% data variables.product.prodname_copilot_short %} tool for the job |
| 28 | + |
| 29 | +While {% data variables.product.prodname_copilot_short %} code completions and {% data variables.product.prodname_copilot_chat_short %} share some functionality, the two tools are best used in different circumstances. |
| 30 | + |
| 31 | +**Code completions work best for**: |
| 32 | + |
| 33 | +* Completing code snippets, variable names, and functions as you write them |
| 34 | +* Generating repetitive code |
| 35 | +* Generating code from inline comments in natural language |
| 36 | +* Generating tests for test-driven development |
| 37 | + |
| 38 | +**Alternatively, {% data variables.product.prodname_copilot_chat_short %} is best suited for**: |
| 39 | + |
| 40 | +* Answering questions about code in natural language |
| 41 | +* Generating large sections of code, then iterating on that code to meet your needs |
| 42 | +* Accomplishing specific tasks with keywords and skills. {% data variables.product.prodname_copilot_chat_short %} has built-in keywords and skills designed to provide important context for prompts and accomplish common tasks quickly. Different types of keywords and skills are available in different {% data variables.product.prodname_copilot_chat_short %} platforms. See "[AUTOTITLE](/copilot/using-github-copilot/asking-github-copilot-questions-in-your-ide#using-keywords-in-your-prompt){% ifversion fpt %}."{% else %}" and "[AUTOTITLE](/copilot/using-github-copilot/asking-github-copilot-questions-in-githubcom#powered-by-skills)."{% endif %} |
| 43 | +* Completing a task as a specific persona. For example, you can tell {% data variables.product.prodname_copilot_chat_short %} that it is a Senior C++ Developer who cares greatly about code quality, readability, and efficiency, then ask it to review your code. |
| 44 | + |
| 45 | +## Create thoughtful prompts |
| 46 | + |
| 47 | +Prompt engineering, or structuring your request so {% data variables.product.prodname_copilot_short %} can easily understand and respond to it, plays a critical role in {% data variables.product.prodname_copilot_short %}'s ability to generate a valuable response. Here are a few quick tips you should remember while crafting your prompts: |
| 48 | + |
| 49 | +* Break down complex tasks. |
| 50 | +* Be specific about your requirements. |
| 51 | +* Provide examples of things like input data, outputs, and implementations. |
| 52 | +* Follow good coding practices. |
| 53 | + |
| 54 | +To learn more, see "[AUTOTITLE](/copilot/using-github-copilot/prompt-engineering-for-github-copilot)." |
| 55 | + |
| 56 | +## Check {% data variables.product.prodname_copilot_short %}'s work |
| 57 | + |
| 58 | +While {% data variables.product.prodname_copilot_short %} is very powerful, it is still a tool capable of making mistakes, and you should always validate the code it suggests. Use the following tips to ensure you are accepting accurate, secure suggestions: |
| 59 | + |
| 60 | +* **Understand suggested code before you implement it.** To ensure you fully understand {% data variables.product.prodname_copilot_short %}'s suggestion, you can ask {% data variables.product.prodname_copilot_chat_short %} to explain the code. |
| 61 | +* **Review {% data variables.product.prodname_copilot_short %}'s suggestions carefully.** Consider not just the functionality and security of the suggested code, but also the readability and maintainability of the code moving forward. |
| 62 | +* **Use automated tests and tooling to check {% data variables.product.prodname_copilot_short %}'s work.** With the help of tools like linting, {% data variables.product.prodname_code_scanning %}, and IP scanning, you can automate an additional layer of security and accuracy checks. |
| 63 | + |
| 64 | +> [!TIP] Optionally, you may want to check {% data variables.product.prodname_copilot_short %}'s work for similarities to existing public code. If you don't want to use similar code, you can turn off suggestions matching public code. See {% ifversion fpt %}"[AUTOTITLE](/copilot/managing-copilot/managing-copilot-as-an-individual-subscriber/managing-copilot-policies-as-an-individual-subscriber#enabling-or-disabling-suggestions-matching-public-code)" or "[AUTOTITLE](/copilot/managing-copilot/managing-github-copilot-in-your-organization/setting-policies-for-copilot-in-your-organization/managing-policies-for-copilot-in-your-organization#policies-for-suggestion-matching)."{% else %}"[AUTOTITLE](/copilot/managing-copilot/managing-copilot-as-an-individual-subscriber/managing-copilot-policies-as-an-individual-subscriber#enabling-or-disabling-suggestions-matching-public-code)," "[AUTOTITLE](/copilot/managing-copilot/managing-github-copilot-in-your-organization/setting-policies-for-copilot-in-your-organization/managing-policies-for-copilot-in-your-organization#policies-for-suggestion-matching)," or "[AUTOTITLE](/copilot/managing-copilot/managing-copilot-for-your-enterprise/managing-policies-and-features-for-copilot-in-your-enterprise#suggestions-matching-public-code)."{% endif %} |
| 65 | + |
| 66 | +## Guide {% data variables.product.prodname_copilot_short %} towards helpful outputs |
| 67 | + |
| 68 | +There are several adjustments you can make to steer {% data variables.product.prodname_copilot_short %} towards more valuable responses: |
| 69 | + |
| 70 | +* **Provide {% data variables.product.prodname_copilot_short %} with helpful context**: |
| 71 | + * If you are using {% data variables.product.prodname_copilot_short %} in your IDE, open relevant files and close irrelevant files. |
| 72 | + * In {% data variables.product.prodname_copilot_chat_short %}, if a particular request is no longer helpful context, delete that request from the conversation. Alternatively, if none of the context of a particular conversation is helpful, start a new conversation. |
| 73 | + * If you are using {% data variables.product.prodname_copilot_chat_dotcom_short %}, provide specific repositories, files, symbols, and more as context. See "[AUTOTITLE](/enterprise-cloud@latest/copilot/using-github-copilot/asking-github-copilot-questions-in-githubcom){% ifversion fpt %}" in the {% data variables.product.prodname_ghe_cloud %} documentation.{% else %}."{% endif %} |
| 74 | + * If you are using {% data variables.product.prodname_copilot_chat_short %} in your IDE, use keywords to focus {% data variables.product.prodname_copilot_short %} on a specific task or piece of context. See "[AUTOTITLE](/copilot/using-github-copilot/asking-github-copilot-questions-in-your-ide#using-keywords-in-your-prompt)." |
| 75 | +* **Rewrite your prompts to generate different responses.** If {% data variables.product.prodname_copilot_short %} is not providing a helpful response, try rephrasing your prompt, or even breaking your request down into multiple smaller prompts. |
| 76 | +* **Pick the best available suggestion.** When you are using code completions, {% data variables.product.prodname_copilot_short %} might offer more than one suggestion. You can use keyboard shortcuts to quickly look through all available suggestions. For the default keyboard shortcuts for your operating system, see "[AUTOTITLE](/copilot/managing-copilot/configure-personal-settings/configuring-github-copilot-in-your-environment#keyboard-shortcuts-for-github-copilot)." |
| 77 | +* **Provide feedback to improve future suggestions.** You can provide feedback in many ways: |
| 78 | + * For code completions, accept or reject {% data variables.product.prodname_copilot_short %}'s suggestion. |
| 79 | + * For individual responses in {% data variables.product.prodname_copilot_chat_short %}, click the thumbs up or thumbs down icons next to the response. |
| 80 | + * For {% data variables.product.prodname_copilot_chat_short %} in your IDE, see "[AUTOTITLE](/copilot/using-github-copilot/asking-github-copilot-questions-in-your-ide#sharing-feedback)" for instructions specific to your environment. |
| 81 | + * For {% data variables.product.prodname_copilot_chat_dotcom_short %}, leave a comment on the [feedback discussion](https://github.com/orgs/community/discussions/110314). |
| 82 | + |
| 83 | +## Stay up-to-date on {% data variables.product.prodname_copilot_short %}'s features |
| 84 | + |
| 85 | +New features are regularly added to {% data variables.product.prodname_copilot_short %} to create new abilities, build on existing features, and improve the user experience. To stay up-to-date with {% data variables.product.prodname_copilot_short %}'s features, see the [changelog](https://github.blog/changelog/label/copilot/). |
0 commit comments