How to Use GitHub Copilot With Conventional Commits Workflows
🔍 WiseChecker

How to Use GitHub Copilot With Conventional Commits Workflows

You want commit messages that follow the Conventional Commits standard — prefixes like feat, fix, and chore — but typing them manually slows you down. GitHub Copilot can generate these structured messages from your staged changes. This article explains how to configure Copilot to produce Conventional Commits and how to use the Copilot Chat panel to refine commit messages. By the end, you will have a repeatable process for creating consistent, scannable commit history.

Key Takeaways: Automating Conventional Commits With GitHub Copilot

  • Copilot Chat > /commit command: Generates a commit message from staged diffs using the Conventional Commits format.
  • VS Code settings.json > github.copilot.chat.commitMessageGeneration.instructions: Custom prompt that forces Copilot to use feat, fix, chore, docs, refactor, test, and style prefixes.
  • Git hooks > prepare-commit-msg: Automatically runs Copilot generation every time you run git commit without a -m flag.

What Conventional Commits Are and How Copilot Fits In

Conventional Commits is a specification for adding human and machine-readable meaning to commit messages. Each message starts with a type keyword such as feat for a new feature, fix for a bug fix, docs for documentation changes, refactor for code restructuring, test for adding or modifying tests, chore for maintenance tasks, and style for formatting changes. An optional scope in parentheses follows the type, for example feat(api). A colon and a space separate the prefix from a short description. A longer body and footer can appear below.

GitHub Copilot uses large language models trained on public code repositories. When you ask it to generate a commit message, it analyzes the diff — the lines added, removed, and modified — and predicts a message that matches common patterns. By default, Copilot may produce messages that do not follow the Conventional Commits format. To enforce the format, you must provide explicit instructions in your editor settings or in the Copilot Chat prompt.

The feature works inside Visual Studio Code, JetBrains IDEs, and GitHub.com Copilot Chat. The setup steps below focus on VS Code because it has the most direct support for commit message generation. The same principles apply to other editors.

Steps to Generate Conventional Commits With GitHub Copilot

Method 1: Use the /commit Command in Copilot Chat

The quickest way to get a Conventional Commit message is through the Copilot Chat panel. This method works with any editor that has Copilot Chat installed.

  1. Stage your changes
    Run git add for the files you want to commit. Copilot reads the staged diff, not the working tree. If nothing is staged, the generated message will be empty or incorrect.
  2. Open Copilot Chat
    In VS Code, press Ctrl+Shift+I or click the Copilot icon in the activity bar. In JetBrains, open the Copilot Chat tool window.
  3. Run the /commit command
    Type /commit in the chat input box and press Enter. Copilot reads the staged diff and returns a commit message in the Conventional Commits format. The message includes a type, an optional scope, a short description, and sometimes a longer body.
  4. Copy and paste the message
    Click the copy button in the chat response. Then run git commit -m "paste here" in the terminal, or paste into the commit message editor if you use a GUI.

Method 2: Customize Copilot Commit Generation Instructions in VS Code

VS Code lets you set a custom instruction file that Copilot reads every time it generates a commit message. This method forces the Conventional Commits format without typing the prompt each time.

  1. Open VS Code settings.json
    Press Ctrl+Shift+P, type Preferences: Open Settings (JSON), and press Enter.
  2. Add the commit message generation setting
    Insert this JSON into the settings object:
    "github.copilot.chat.commitMessageGeneration.instructions": [
    {
    "text": "Generate a commit message following the Conventional Commits specification. Use one of these types: feat, fix, docs, refactor, test, chore, style. Include an optional scope in parentheses after the type. Use present tense, imperative mood. Keep the first line under 72 characters. Add a blank line and a body if the change requires explanation."
    }
    ]
  3. Save settings.json
    Press Ctrl+S to save. No restart is needed.
  4. Stage files and open the commit editor
    Run git add . then git commit without the -m flag. VS Code opens the commit message editor. The Copilot icon appears in the editor toolbar.
  5. Click the sparkle icon or press Ctrl+Enter
    Copilot generates a commit message based on the staged diff and your custom instructions. The message appears in the editor. Edit it if needed, then save and close the editor to complete the commit.

Method 3: Use a prepare-commit-msg Git Hook

A Git hook automates the generation so you never have to click a button. This approach works with any editor that supports command-line Copilot generation.

  1. Navigate to your repository’s hooks folder
    Open a terminal and run cd .git/hooks inside your repository root.
  2. Create the prepare-commit-msg file
    Run touch prepare-commit-msg on Linux or macOS, or type nul > prepare-commit-msg on Windows. Then open the file in a text editor.
  3. Add the hook script
    Paste this script:
    #!/bin/sh
    COMMIT_MSG_FILE=$1
    COMMIT_SOURCE=$2
    
    # Only generate if no -m flag was used
    if [ "$COMMIT_SOURCE" = "message" ]; then
      exit 0
    fi
    
    # Run Copilot generation and overwrite the commit message file
    git diff --cached | gh copilot explain --output commit_message > "$COMMIT_MSG_FILE"
    

    This script uses the GitHub CLI gh copilot explain command, which requires the GitHub CLI version 2.40 or newer with the Copilot extension enabled.

  4. Make the hook executable
    Run chmod +x prepare-commit-msg on Linux or macOS. On Windows, skip this step.
  5. Stage files and commit
    Run git add . then git commit. The hook runs, Copilot generates a message, and the commit editor opens with the generated text. Edit and save as usual.

Common Issues With Copilot and Conventional Commits

Copilot Ignores the Conventional Commits Format

If Copilot returns messages like Update file or Fixed bug without a type prefix, the custom instructions are not being applied. Check that the github.copilot.chat.commitMessageGeneration.instructions setting is in your user settings.json, not the workspace .vscode/settings.json. Workspace settings override user settings only if the workspace file contains the same key. Also verify that the JSON syntax is valid — a missing comma or bracket will cause VS Code to ignore the setting silently.

The /commit Command Returns a Generic Message

The /commit command in Copilot Chat does not automatically read your custom instructions. It uses a built-in prompt. To get Conventional Commits from the chat panel, you must include the format rules in your chat prompt. For example: Write a Conventional Commit message for this diff. Use types feat, fix, docs, refactor, test, chore, style. This works reliably but requires typing the prompt each time. For a permanent solution, use Method 2 or Method 3 instead.

Git Hook Does Not Run or Produces Errors

If the gh copilot explain command fails, install or update the GitHub CLI and the Copilot extension. Run gh extension install github/gh-copilot. Then test the command manually: git diff --cached | gh copilot explain --output commit_message. If the output is empty, make sure files are staged. If the hook does not run, verify the file name is exactly prepare-commit-msg with no extension, and that the shebang line #!/bin/sh is present and correct.

Copilot Chat vs Custom Instructions vs Git Hook: Key Differences

Item Copilot Chat /commit VS Code Custom Instructions Git Hook (prepare-commit-msg)
Setup effort None One-time settings edit One-time script creation per repo
Format consistency Requires manual prompt each time Automatic for every commit Automatic for every commit
Works without GUI No No Yes
Supports custom scope Yes, if you specify in prompt Yes, via instruction text Yes, via instruction text
Requires GitHub CLI No No Yes

You now have three ways to generate Conventional Commits with GitHub Copilot. Start with the /commit command in Copilot Chat to test the output. If you work in VS Code and want a zero-effort workflow, configure the custom instructions in settings.json. For teams that want consistent formatting across all editors, deploy the Git hook in each repository. After setting up your preferred method, try combining Conventional Commits with Copilot’s code generation features — for example, ask Copilot to generate a feat commit message that matches the function it just wrote for you.