Copilot  

How to set custom instructions for GitHub Copilot

Introduction

In this article, we will explore the custom instructions available for GitHub Copilot. Using the custom instructions, you can make GitHub Copilot like a team member who.

They are familiar with the coding standards and guidelines you follow during development.

What are custom instructions?

Now, everyone has started using GitHub Copilot for day-to-day development work, and each person has a unique approach to asking questions or providing prompts to Copilot, resulting in varied responses that depend on the specific questions or prompts. What if everyone gets the reactions in the same format? Sounds interesting, right? Here, the custom instructions come into the picture.

Using the custom instructions, the copilot gives you responses and generates the code as per your coding standards, guidelines, or rules you are following in the project once you set the custom instructions. So, when you use Ask, Edit, or Agent mode during development, it will use those instructions as context and give you responses or generate code in that way. It uses simple natural language instructions in the file and follows the Markdown format with the extension .md

Custom instruction types

The copilot supports multiple methods for defining custom instructions for your project.

  • .github/copilot-instructions.md file: Define project-wide code-generation instructions in a single Markdown file that's auto-included in every Copilot request across supported editors and IDEs.
  • Instructions.md files: Create Markdown-based code-generation instruction files with glob pattern support for task-specific control, auto-included in Copilot chats in VS Code.
  • VS Code settings: Define instructions in VS Code settings or files for tasks like code generation, tests, commits, and PRs—ideal for broader guidance beyond coding.

Create a custom instruction file

There are ways to create instruction files in your workspace or user profile. Workspace instruction files apply only to the current workspace, while user

instruction files are accessible across all workspaces. You can also manually create the instruction file under the '.github' folder.

To create an instruction file

Step 1. Click on the Configure chat or settings icon and select the Instructions option.

Instructions option

Step 2. You will get the two options to select, select the first option, and then it will create the empty *. instructions.md file at '.github/instructions' folder in your workspace after providing the file name.

Workspace

Then select the location as below:

Location

Provide the name for your file. Here, we provided a 'copilot'.

Copilot

Once you hit enter, it will create the file as shown below, according to the file name '.github/instructions/copilot.instructions.md'.

Apply

If you select the second option, as per your project, it will auto-generate the instructions file in the '.github' folder with the name 'copilot-instructions.md' with the default instructions, then you can review and modify as per your requirement.

Github copilot

Sample instructions

This is just a sample of instructions. I have added them in the '.github/copilot-instructions.md' file as below:

  • When creating new features in Python, please follow these guidelines.
  • Use the camelCase naming convention for functions and variables
  • Use 'func_' prefix for all function names

Custom instructions in action

As soon as the instructions are saved in a file, they will be automatically attached to requests that you submit in either the Copilot Chat view or in inline chat, in VS Code and Visual Studio.

In the below screenshot, you can see that after sending the prompt, it took the 'copilot-instructions.md' file automatically as a reference.

chat

Let's check the response and see if it follows the instructions. Here, it follows the instruction about creating the function name with the prefix 'func_'.

Addition

Structuring Custom Instructions for Maximum Impact

  • Write clear, self-contained instructions: Keep each instruction short and simple - use separate lines for multiple ideas, and avoid referencing external resources.
  • Organize instructions effectively: Split instructions into multiple files based on topics or task types for better organization and clarity.
  • Enable easy sharing and tracking: Store instructions in files for easy sharing across teams or projects, and use version control to track changes.
  • Apply and reuse instructions smartly: Use the applyTo property to target specific files or folders, and reference custom instructions in prompt files to keep them clean and focused.

Conclusion

In this article, we explored GitHub Copilot custom instructions, their key features, setup process, and how to use them for generating responses based on instructions. If you have any questions or suggestions, feel free to reach out.

“Learn It, Share it.”