Copilotintermediate

How to Generate Git Commits and PR Descriptions with GitHub Copilot CLI

Learn to use GitHub Copilot CLI for automatic commit message generation, PR descriptions, and git workflow automation. Includes customization for conventional commits.

12 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

GitHub Copilot CLI brings AI-powered assistance directly to your terminal, helping you understand git commands, automate workflows, and boost productivity. This guide covers how to use Copilot for commit message generation, PR descriptions, and git workflow automation across different platforms.

Prerequisites

Before you begin, ensure you have:

  • GitHub account with an active Copilot subscription (Pro, Pro+, Business, or Enterprise)
  • GitHub CLI (gh) installed on your system
  • Git installed and configured
  • Terminal access (macOS Terminal, Windows PowerShell 6+, or Linux shell)

Installing GitHub Copilot CLI

GitHub Copilot CLI can be installed using several methods depending on your operating system.

macOS Installation

Using Homebrew (Recommended):

brew install copilot-cli

Using the install script:

curl -fsSL https://gh.io/copilot-install | bash

To install system-wide (to /usr/local/bin):

curl -fsSL https://gh.io/copilot-install | sudo bash

Windows Installation

Using WinGet:

winget install GitHub.Copilot

Using npm:

npm install -g @github/copilot

Note: Native Windows PowerShell support is experimental. For the best experience on Windows, use WSL (Windows Subsystem for Linux).

Linux Installation

Using Homebrew:

brew install copilot-cli

Using the install script:

curl -fsSL https://gh.io/copilot-install | bash

Using npm:

npm install -g @github/copilot

Authentication

After installation, authenticate with your GitHub account:

gh auth login

Or set the GH_TOKEN or GITHUB_TOKEN environment variable with your personal access token.

Using Copilot CLI for Git Commands

GitHub Copilot CLI provides two primary commands: suggest for generating commands and explain for understanding existing commands.

The Suggest Command

Use gh copilot suggest to get AI-generated command suggestions:

# Get help with git commands
gh copilot suggest "how to undo my last commit" -t git

# Suggest shell commands for git operations
gh copilot suggest "delete a branch locally and remotely" -t git

# Get help with complex git workflows
gh copilot suggest "squash the last 3 commits into one" -t git

The -t git flag targets git-specific suggestions. Other targets include shell and gh (GitHub CLI).

Setting Up Aliases

For faster access, set up shell aliases:

gh copilot alias

This generates configuration for:

  • ghcs - Alias for gh copilot suggest
  • ghce - Alias for gh copilot explain

Add the generated configuration to your shell profile (.bashrc, .zshrc, or PowerShell profile).

The Explain Command

Use gh copilot explain to understand complex git commands:

# Understand a rebase command
gh copilot explain "git rebase -i HEAD~5"

# Explain a complex git log format
gh copilot explain "git log --oneline --graph --decorate --all"

Commit Message Generation

While Copilot CLI focuses on command suggestions, commit message generation is available through integrated tools.

VS Code Integration

VS Code offers the most robust commit message generation:

  1. Stage your changes using the Source Control panel
  2. Click the sparkle icon (AI-generated commit message) in the commit message box
  3. Review and edit the suggested message
  4. Commit your changes

Customizing Commit Message Format

Configure VS Code to generate conventional commits:

In settings.json:

{
  "github.copilot.chat.commitMessageGeneration.instructions": [
    { "text": "Use conventional commit format: type(scope): description" },
    { "text": "Use imperative mood: 'Add feature' not 'Added feature'" },
    { "text": "Keep subject line under 50 characters" },
    { "text": "Use types: feat, fix, docs, style, refactor, perf, test, chore, ci" },
    { "text": "Include scope when relevant (e.g., api, ui, auth)" },
    { "text": "Reference issue numbers with # prefix" }
  ]
}

Using an instructions file:

Create .copilot-commit-message-instructions.md in your repository root:

# Commit Message Format

Generate commit messages following these rules:

1. Use conventional commit format: type(scope): description
2. Types: feat, fix, docs, style, refactor, perf, test, chore, ci
3. Keep the subject line under 50 characters
4. Use imperative mood ("Add" not "Added")
5. Reference related issue numbers when applicable

## Examples

- feat(auth): add OAuth2 login support
- fix(api): resolve null pointer in user endpoint
- docs(readme): update installation instructions

Then reference it in your settings:

{
  "github.copilot.chat.commitMessageGeneration.instructions": [
    { "file": ".copilot-commit-message-instructions.md" }
  ]
}

GitHub Desktop Integration

GitHub Desktop includes built-in Copilot commit message generation:

  1. Open GitHub Desktop and view your changes
  2. Click the Copilot button in the commit message area
  3. Review the suggested message and edit if needed
  4. Click Commit

This feature is available to all Copilot users, including those on Copilot Free (with limitations).

GitHub.com Integration

When editing files directly on GitHub.com:

  1. Make your changes to the file
  2. Click "Commit changes"
  3. Copilot automatically suggests a title and description
  4. Review and modify as needed before committing

PR Description Generation

Creating comprehensive pull request descriptions is another area where Copilot excels.

VS Code Pull Request Extension

With the GitHub Pull Requests extension:

  1. Create your branch and make changes
  2. Open the GitHub tab in VS Code
  3. Click "Create Pull Request"
  4. Click the sparkle icon to generate title and description
  5. Review and customize the generated content

Using PR Templates with Copilot:

If your repository has a PR template, pre-paste it into the description box before clicking the generate button. Copilot will fill in the sections while preserving your template structure.

GitHub.com PR Summaries

On GitHub.com when creating or reviewing PRs:

  1. Open the PR creation page or view an existing PR
  2. Click the Copilot icon to generate a summary
  3. Review the AI-generated description of changes
  4. Edit to add context specific to your team's needs

Visual Studio Integration

In Visual Studio 2022 (version 17.10+):

  1. Open the Create Pull Request window
  2. Click the sparkle icon (Add AI Generated Pull Request Description)
  3. Review and edit the generated description

Changelog and Release Notes Automation

GitHub provides built-in release notes automation that works alongside Copilot.

Automatic Release Notes

Configure .github/release.yml for automated changelogs:

changelog:
  exclude:
    labels:
      - ignore-for-release
    authors:
      - dependabot
  categories:
    - title: Breaking Changes
      labels:
        - breaking-change
        - Semver-Major
    - title: New Features
      labels:
        - enhancement
        - feature
    - title: Bug Fixes
      labels:
        - bug
        - fix
    - title: Documentation
      labels:
        - documentation
    - title: Other Changes
      labels:
        - "*"

When creating a release, GitHub automatically generates notes based on merged PRs and this configuration.

Using Copilot for Release Summaries

For more detailed release notes, use Copilot Chat:

@workspace Generate release notes summarizing the changes in the last 10 commits.
Group by feature, fix, and documentation changes.

Git Workflow Integration

Copilot CLI Agent Mode

The Copilot CLI agent can execute multi-step git workflows:

# Start an interactive session
copilot

# Ask for help with complex workflows
> Help me set up a git workflow that creates a feature branch,
> makes a commit, and prepares a PR

The agent can:

  • Analyze your repository structure
  • Execute git commands (with your approval)
  • Create branches and commits
  • Interface with GitHub for PR creation

Security Controls

Control which commands Copilot can execute:

# Allow all tools except dangerous ones
copilot --allow-all-tools --deny-tool 'shell(rm)' --deny-tool 'shell(git push --force)'

Custom Agents for Git Workflows

Create a custom agent profile for your team's git workflow:

Create .github/agents/git-workflow.md:

# Git Workflow Agent

You are a git workflow assistant for our team.

## Conventions
- Branch naming: feature/TICKET-description, fix/TICKET-description
- Commit format: conventional commits
- PR titles: [TICKET] Description

## Available Commands
- Create feature branches
- Generate commit messages
- Prepare PR descriptions
- Suggest reviewers based on changed files

Platform-Specific Notes

macOS

  • Terminal.app and iTerm2 both work well with Copilot CLI
  • Use Homebrew for easy installation and updates
  • Shell completion available for zsh (default on macOS)

Windows

  • WSL recommended for full feature support
  • Native PowerShell 6+ works but is experimental
  • Windows Terminal provides the best experience
  • Some shell-specific features may behave differently

Linux

  • Full support across major distributions
  • Works with bash, zsh, fish, and other shells
  • Can be installed via Homebrew, npm, or direct download
  • Integrates with popular terminals (GNOME Terminal, Konsole, etc.)

Troubleshooting

Authentication Issues

If Copilot CLI fails to authenticate:

# Re-authenticate with GitHub
gh auth login --web

# Verify authentication status
gh auth status

Slow Suggestions

If suggestions are slow:

  1. Check your internet connection
  2. Verify you're not behind a restrictive firewall
  3. Try resetting the Copilot cache:
    gh copilot config clear
    

Commit Message Quality

If generated commit messages don't match your expectations:

  1. Add more specific instructions in your settings
  2. Stage related changes together (don't mix unrelated changes)
  3. Use conventional commit keywords in your instruction file
  4. Review and refine the .copilot-commit-message-instructions.md file

Best Practices

  1. Always review generated content - AI suggestions may not capture full context
  2. Use consistent formatting - Configure instructions for your team's conventions
  3. Stage related changes together - Better context leads to better suggestions
  4. Keep instructions updated - Refine your configuration as you learn what works
  5. Combine with PR templates - Use templates alongside AI generation for consistency

Additional Resources


Need help optimizing your development workflow? Inventive HQ offers consulting services for development tooling, CI/CD pipelines, and AI-assisted development practices. Contact us for expert guidance.

Frequently Asked Questions

Find answers to common questions

While the gh-copilot extension's suggest command can help with git commands, native commit message generation from the CLI is not yet available. However, VS Code, GitHub Desktop, and GitHub.com all support Copilot-powered commit message generation. You can use Copilot CLI to suggest git commands and workflows.

Need Professional IT & Security Help?

Our team of experts is ready to help protect and optimize your technology infrastructure.