Copilot’s core toolkit

GitHub Copilot is a generative AI pair programmer, which means it creates new code based on what it has learned. Because of that, it may deliver different solutions to the same prompt across sessions—that’s expected behavior. To use it, you need a GitHub account and a Copilot license, plus the extension installed and authenticated in your editor.

Code completion

Start with a new Python file named rock_paper_scissor.py. At the top, add a comment that describes the game you want to build:

Create a Rock Paper Scissors game where the player inputs their choice and plays against a computer that randomly selects its move, with the game showing who won each round. Add a score counter that tracks player and computer wins, and allow the game to continue until the player types ‘quit’.

Press Enter a couple of times. Gray, italicized text will appear after your cursor—this is ghost text, Copilot’s suggestion. Press Tab to accept it. Keep accepting lines until the suggestion defines a function, i.e., begins with the def keyword.

After the function definition, hover over the ghost text to see the available actions: accept a single word, cycle through completions, or accept the whole suggestion. The three-dot menu includes “Open Completions Panel,” which lists multiple ways the code could be implemented. Scroll through, pick one, and click “Accept suggestion” to populate the code.

Add a line to invoke the function, then run the game from the terminal:

python rock_paper_scissor.py

The game accepts text input; type quit to exit.

Screenshot of the output of rock paper scissors.py in the terminal

Inline chat for quick changes

To refine a specific line of code, highlight it and press Ctrl + I (or Command + I). This opens Copilot Inline Chat. For example, if you have a line that expects the user to type “rock”, “paper”, or “scissors” in full:

player_choice = input('Rock, Paper, Scissors or Quit: ').lower()

you can prompt Copilot to accept single-letter shortcuts like “r”, “p”, and “s”:

allow the user to enter r for rock, p for paper, and s for scissors

Before sending, check the dropdown at the end of the prompt window to select a model. Copilot Chat supports several models, with new ones added continually.

multimodal in inline chat

After Copilot updates the code, accept or discard the change. Run the game again—single-letter choices now work. Inline chat is best for targeted fixes; for broader work, use the full Copilot Chat experience.

Copilot Chat and building a GUI

Copilot Chat handles code explanations, building minimal viable products, writing tests, and fixing terminal errors. As a demonstration, use it to add a graphical user interface (GUI) to the rock-paper-scissors game.

Open the chat icon in VS Code’s left-hand bar, then enter a prompt asking for a GUI version:

Create a simple GUI using a library like Tkinter for the game

The chat panel lists rock_paper_scissor.py as the current file—this context tells Copilot which game you mean. Keep the file open so the context stays accurate. You can disable it with the Close File icon, but for this task keep it enabled.

Screenshot of the chat window with an arrow pointing to the current file

Pick a model (for example, Claude 3.5 Sonnet) and send the request. Copilot’s response will include a plan, the code block, and citations you can inspect via “View matches”.

At the bottom of the suggestion in the Chat panel, the icons from left to right let you:

  • Read the code aloud
  • Retry the same prompt for a different response
  • Upvote the provided code
  • Downvote the provided code
  • Edit the suggestion using Copilot

Hover over the code block itself—three icons appear in the top-right corner:

  • Apply in Editor: replace the current file with this code
  • Insert At Cursor: place the code at your cursor
  • Copy: copy to clipboard
  • More: “Insert into Terminal” or “Insert into New File”
Screenshot with the four buttons described above circled

Click “Apply in Editor”, then accept the changes at the top of the file. Run the game—you now have a GUI-based version.

Slash commands and context

Slash commands are shortcuts for common prompts. Type / in the Copilot Chat window to see available commands, such as /explain for a full explanation of your current file. The /help command lists all slash commands and what they do.

Screenshot showing the list of commands that comes up when a user types /help.

For a fuller list, the Copilot Chat cheat sheet covers common commands.

Context matters—without additional inputs, Copilot only knows what’s in your open file. To extend that, use chat variables like #file to point at a specific file or #codebase to search across your whole project. The chat variables documentation shows the full set.

Chat participants and Copilot Edits

Type @ in the chat window to invoke a specialist participant. @workspace knows your entire workspace—useful for locating a function definition or generating a README. @terminal has context from the integrated terminal, and @github knows your repository, pull requests, issues, and can search the web.

Screenshot showing some of the available chat participants

The cheat sheet also lists common participants.

Copilot Edits combines the conversational flow of Chat with the rapid feedback of inline chat, and can edit multiple files at once. To add a scoreboard to the game, open the Copilot menu in VS Code and select “Open Copilot Edits”, then enter a prompt asking to add a detailed scoreboard to keep track of game statistics:

Add a detailed scoreboard to track and display the number of ties, player wins, and computer wins for each round.
Screenshot with an arrow pointing the Copilot icon and displaying the dropdown menu that appears when you click it.

Choose a model and send. After the response streams in, click “Accept” and run the game—the GUI should now track stats as you play. Edits targeting multiple files at once become especially valuable in larger projects.

Final polish: commits and code review

With the game done, stage your changes in VS Code’s source control panel. Next to the commit message box, click the sparkles icon to have Copilot generate a commit message for you.

Before pushing, you can also get a code review. Highlight a section of code, click the sparkle icon that appears above it, and select “Review using Copilot”. This gives you initial feedback before you ask your team for a final review:

Select the 'Review using Copilot' option.

Copilot code review is also available directly through github.com if you prefer that flow. Note that not every IDE exposes the same Copilot features—JetBrains IDEs, for instance, offer Copilot Code Complete and Copilot Chat but not all the other functions described above.

Putting Copilot to work

GitHub Copilot is more than an autocomplete tool. It functions as a conversational pair programmer that can explain code, propose fixes, and handle multi-file edits. The features above cover the core workflows you'll use daily, but a few additional settings and habits will make the experience smoother.

Wielding the tools effectively

Using inline chat well means knowing when to engage it. Select a block of code and ask a specific question—like "What does this function do?"—rather than vague prompts. The chat panel is better for broader discussions about an entire file or repository, while the inline chat is best for targeted changes.

For multi-line edits, the tab key is your friend. Copilot will propose complete changes across several lines, and you can accept or reject them with Tab or Esc. If a suggestion isn't quite right, edit the prompt and try again.

Managing context and customizing behavior

Copilot's accuracy depends heavily on the context it has. In chat, use @file mentions to add specific files to the conversation. For large codebases, configure custom instructions in a .github/copilot-instructions.md file—this tells Copilot about your project's style, testing requirements, or coding standards.

You can also block optional content types like specific paths or code patterns via policies. For privacy, ensure your repository isn't public if you want to avoid Copilot training on your code, though only code matching certain license types may be used for training.

Handling common snags

  • Slow or stale suggestions: Clear the chat conversation and re-add necessary context files.
  • Incorrect code: Rephrase your prompt with more specifics, or break the request into smaller steps.
  • Missing completions: Confirm Copilot is enabled in your editor and that the language is supported.

Where to go from here

The features described above are the foundation for effectively using Copilot. It's a versatile tool that extends far beyond simple code completion.

Ready to test these features yourself? Try GitHub Copilot in your own editor.