githubgithub-copilot

GitHub Copilot removes important comments when using "auto-apply"


I'm working on a few Python projects that are specifically designed for teaching programming to students. In these projects, I include detailed comments that explain exactly what each part of the code does - sometimes in a very verbose way - because clarity and thorough explanation are essential for beginners.

However, when I use GitHub Copilot's "auto-apply" feature to apply suggestions automatically, I've noticed that many of my comments are being removed or replaced. This often strips away important context that I've written for learners.

My questions:

Here's what I've tried:


Solution

  • Instructions are the best way to accomplish this, but you don't have to copy paste in every repo either. 😉 If you log into your GitHub and go to the Copilot page, there's a special spot for Personal instructions. Try to avoid putting too much in there, because those are applied in every scenario across the board whenever you're signed in and using Copilot. If anything at any point ends up clashing with each other, then Copilot just gets weird and might guess one option or another and sometimes something completely different altogether. Add a safeguard with a well-defined conditional to be on the safe side.

    Another option is to create a central repository with a .github/instructions/specific-name.instructions.md file and then reference it with the built-in Copilot tool called #githubRepo with the fully qualified name of the repo (username/repo-name) along with the file path. That get's a little long to repeat in every prompt, but a custom URL to a private instruction is fine to add as a markdown link from the instructions file itself. That way your copy-paste is a little shorter and the logic is centralized. Note: In order for these regular instructions to work, it has to have an applyTo defined in the frontmatter. Just point it to **/* for "all files". This would work best if you plan on adding anything more to those "don't delete my comments" instructions. Otherwise, stick to the personal instructions version 😀

    [