Using a GitHub Copilot instructions file

by
, , 2 min read

When using GitHub Copilot inside VS Code, as well as prompts we can set instructions at the repo level to give the AI a set of guidelines to follow.

If we have team preferences, coding standards or a list of things to avoid we can set all of this in one place so it does not have to be spelled out again and again in each new chat.

The instructions file is in Markdown format and placed at the root, like this.

.github/copilot-instructions.md

Create the .github directory if you don't already have one then a new Markdown file called copilot-instructions.md.

You can also create more specific instructions for selected directories or to match certain files type if you want it to be more granular.

Instructions are written in natural language, just as with a prompt. You can use the Markdown features to help organise the instructions and make them more readable, like a readme.md file.

Here's an example, which I created:

# Project Overview

This project is a web application that allows users to capture data in structured questionnaires.

It is built using a C# backend and Stencil.js web components for the front end.

## Folder Structure

Follow the existing naming conventions.

C# folders and files are in TitleCase.

Any JavaScript or other front end folders and files are in kebab-case.

## Libraries and Frameworks

Use Stencil.js with .scss files to create web components on the frontend.

Use C# for the backend.

Avoid using deprecated libraries or APIs.

Avoid using jQuery for any new code.

Do not introduce any new libraries or frameworks unless specifically asked to do so.

## Coding Standards

### JavaScript

Encourage the use of TypeScript for new code.

In JavaScript, use camelCase for variable and function names.

Favour modern JavaScript features (e.g. arrow functions, async/await) over older patterns (e.g. var, function(){}).

### CSS

In CSS, prefer Flexbox or Grid layout over older layout techniques (e.g. float, display: table).

In CSS, prefer logical properties (e.g. margin-inline-start) over physical properties (e.g. margin-left).

## Web Accessibility

Ensure that all markup is accessible, using semantic tags and adding additional markup to support non screen users where appropriate.

## Ignore

The following folders contain configuration or generated code and can be ignored:

dist/
build/
out/
.vscode
.env
.git/

This is something that will need to be reviewed and honed over time.

Official documentation: Adding repository custom instructions for GitHub Copilot