DEV Community

Cover image for Boost Your Team's Productivity with GitHub Copilot Custom Instructions
Andrea Liliana Griffiths
Andrea Liliana Griffiths

Posted on

Boost Your Team's Productivity with GitHub Copilot Custom Instructions

As developers, we're constantly looking for ways to optimize our workflows and increase productivity. GitHub Copilot has already transformed the way many of us write code, but did you know you can customize it to better align with your team's specific practices and preferences?

In this article, I'll explore how to leverage GitHub Copilot's repository custom instructions and prompt files to supercharge your team's development workflow.

The Problem: Generic AI Assistance

By default, GitHub Copilot provides good code suggestions, but it lacks awareness of your team's specific:

  • Coding conventions and style preferences
  • Project architecture and patterns
  • Tech stack and tooling choices
  • Workflow processes

This means you often need to manually adjust Copilot's suggestions or repeatedly provide the same context in your queries, which can slow you down.

The Solution: Repository Custom Instructions

GitHub Copilot now allows you to create a file in your repository that automatically adds contextual information to all questions you ask Copilot Chat. This means more tailored responses without repeatedly explaining your team's practices.

Setting Up Repository Custom Instructions

Creating repository custom instructions is straightforward:

  1. Create a file at .github/copilot-instructions.md in the root of your repository
  2. Add natural language instructions in Markdown format
  3. Save the file - it's immediately available to Copilot Chat

The custom instructions will be automatically included with every chat prompt you send, though they won't be visible in the chat interface itself.

Sample Instructions

Here's an example of what your instructions might look like:

We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.

We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.

Our team uses Jira for tracking items of work.
Enter fullscreen mode Exit fullscreen mode

These simple instructions will ensure Copilot consistently provides suggestions that align with your team's practices.

Writing Effective Custom Instructions

For best results, keep your instructions:

  • Short and self-contained: Focus on specific practices and preferences
  • Contextual: Add relevant information that supplements users' questions
  • Clear: Use direct language that explains your team's practices

What to Avoid

The following types of instructions are unlikely to work well:

  • Requests to refer to external resources when formulating a response
  • Instructions to answer in a particular style
  • Requests to always respond with a certain level of detail

For example, these instructions would likely be ineffective:

Always conform to the coding styles defined in styleguide.md in repo my-org/my-repo when generating code.

Use @terminal when answering questions about Git.

Answer all questions in the style of a friendly colleague, using informal language.

Answer all questions in less than 1000 characters, and words of no more than 12 characters.
Enter fullscreen mode Exit fullscreen mode

Taking It Further: Prompt Files

For VS Code users, GitHub Copilot offers an even more powerful feature: prompt files. These allow you to build and share reusable prompt instructions with additional context.

Prompt files (.prompt.md) let you create standardized templates for common tasks. Unlike repository custom instructions which apply globally, prompt files are used for specific interactions.

Setting Up Prompt Files

  1. Configure the chat.promptFiles VS Code setting
  2. Create a .prompt.md file in the .github/prompts directory
  3. Write prompt instructions using Markdown
  4. Reference workspace files as needed using Markdown links

Practical Use Cases for Prompt Files

Prompt files excel at standardizing repetitive tasks:

Code Generation

Create templates for generating components, tests, or migrations:

Your goal is to generate a new React form component.

Ask for the form name and fields if not provided.

Requirements for the form:
- Use form design system components: [design-system/Form.md](../docs/design-system/Form.md)
- Use `react-hook-form` for form state management:
  - Always define TypeScript types for your form data
  - Prefer *uncontrolled* components using register
  - Use `defaultValues` to prevent unnecessary rerenders
- Use `yup` for validation:
  - Create reusable validation schemas in separate files
  - Use TypeScript types to ensure type safety
  - Customize UX-friendly validation rules
Enter fullscreen mode Exit fullscreen mode

Security Practices

Standardize security reviews:

Secure REST API review:
- Ensure all endpoints are protected by authentication and authorization
- Validate all user inputs and sanitize data
- Implement rate limiting and throttling
- Implement logging and monitoring for security events
Enter fullscreen mode Exit fullscreen mode

Real-World Benefits

Implementing custom instructions and prompt files can yield significant benefits:

  1. Consistency: Ensure all team members receive code suggestions that follow your team's standards
  2. Efficiency: Reduce time spent manually adjusting Copilot's suggestions
  3. Onboarding: Help new team members learn your practices through AI assistance
  4. Quality: Reduce bugs and issues caused by inconsistent code patterns

Getting Started: A Step-By-Step Plan

Ready to implement this for your team? Here's a practical approach:

  1. Audit Your Practices: Document your team's current coding conventions, tooling preferences, and workflow patterns
  2. Create Base Instructions: Draft an initial .github/copilot-instructions.md file
  3. Identify Common Tasks: List repetitive coding tasks that would benefit from standardized prompts
  4. Develop Prompt Files: Create .prompt.md files for these common tasks
  5. Train Your Team: Ensure everyone knows how to use these features
  6. Iterate: Refine your instructions based on team feedback

Simples!

By customizing GitHub Copilot with repository instructions and prompt files, you're essentially teaching your AI assistant to become a more integrated member of your development team. This small investment in configuration can lead to significant productivity gains over time.

As AI coding assistants continue to evolve, the teams that will benefit most are those who effectively customize these tools to complement their specific workflows and practices.

Have you implemented custom instructions for GitHub Copilot? Share your experiences and tips in the comments!


This article is based on GitHub's documentation as of publishing date for repository custom instructions and prompt files for GitHub Copilot. Features may evolve over time, so always refer to the official documentation for the most up-to-date information.

Top comments (1)

Collapse
 
bernert profile image
BernerT

Great breakdown of how to tailor Copilot to a team's needs! I didn’t realize you could use prompt files in VS Code to standardize tasks—definitely going to try that out. Thanks for the practical tips!