Skip to content

GitHub Copilot Cheat Sheet

GitHub Copilot is an AI-powered code completion tool developed by GitHub and OpenAI. It provides intelligent code suggestions, generates entire functions, and assists with documentation and testing. Copilot integrates seamlessly with popular IDEs and supports dozens of programming languages.

⚠️ Note: Requires GitHub Copilot subscription ($10/month individual, $19/month business)

# Install via VS Code Extensions
# Search for "GitHub Copilot" in Extensions marketplace
# Or install via command line
code --install-extension GitHub.copilot
code --install-extension GitHub.copilot-chat
# Install via JetBrains Plugin Repository
# Go to File > Settings > Plugins
# Search for "GitHub Copilot" and install
# Install via plugin manager (e.g., vim-plug)
Plug 'github/copilot.vim'

# Or using packer.nvim
use 'github/copilot.vim'
# Authenticate with GitHub account
:Copilot setup

# Check authentication status
:Copilot status

# Sign out
:Copilot signout
// Type function signature and let Copilot suggest implementation
function calculateTax(income, rate) \\\\{
  // Copilot will suggest: return income * rate;
\\\\}

// Start typing comment to get function suggestion
// Calculate fibonacci sequence
// Copilot will suggest complete function
# Open Copilot Chat
Ctrl+Shift+I (VS Code)

# Quick chat
Ctrl+I (VS Code)

# Explain selected code
/explain

# Fix selected code
/fix

# Generate tests
/tests

# Generate documentation
/doc
ShortcutActionIDE
TabAccept suggestionAll
Ctrl+]Next suggestionVS Code
Ctrl+[Previous suggestionVS Code
EscDismiss suggestionAll
Ctrl+EnterOpen suggestions panelVS Code
Ctrl+Shift+IOpen Copilot ChatVS Code
Ctrl+IQuick chatVS Code
Alt+]Next suggestionJetBrains
Alt+[Previous suggestionJetBrains
# Explain code functionality
/explain What does this function do?

# Fix bugs in selected code
/fix This function has a memory leak

# Generate unit tests
/tests Create comprehensive tests for this class

# Optimize performance
/optimize Make this algorithm more efficient

# Generate documentation
/doc Create JSDoc comments for this function

# Refactor code
/refactor Extract this into smaller functions
# Create issue-to-PR workflow
# 1. Assign GitHub issue to Copilot Workspace
# 2. Copilot analyzes requirements
# 3. Generates implementation plan
# 4. Creates code across multiple files
# 5. Submits pull request for review
// Provide clear context in comments
/**
 * User authentication service for e-commerce platform
 * Handles login, logout, and session management
 * Uses JWT tokens and Redis for session storage
 */
class AuthService \\\\{
  // Copilot will generate contextually appropriate methods
\\\\}

// Use descriptive variable names
const userAuthenticationToken = // Copilot suggests JWT implementation
const databaseConnectionPool = // Copilot suggests database setup
// Interface definitions help Copilot understand structure
interface User \\\\{
  id: string;
  email: string;
  preferences: UserPreferences;
\\\\}

// Copilot will suggest type-safe implementations
function updateUser(user: User) \\\\{
  // Suggestions will respect TypeScript types
\\\\}
# Type hints improve suggestions
from typing import List, Dict, Optional

def process_data(items: List[Dict[str, Any]]) -> Optional[Dict[str, int]]:
    # Copilot provides type-aware suggestions
    pass

# Docstrings provide context
def calculate_metrics(data):
    """
    Calculate performance metrics for machine learning model
    Args:
        data: Training data with features and labels
    Returns:
        Dictionary with accuracy, precision, recall metrics
    """
    # Copilot suggests ML-specific implementations
// Component props help Copilot understand structure
interface ButtonProps \\\\{
  variant: 'primary'|'secondary';
  size: 'small'|'medium'|'large';
  onClick: () => void;
\\\\}

// Copilot suggests complete component implementation
const Button: React.FC<ButtonProps> = (\\\\{ variant, size, onClick \\\\}) => \\\\{
  // Suggestions include proper JSX and styling
\\\\};
// ❌ Vague context
function process() \\\\{
  // Limited suggestions
\\\\}

// ✅ Clear context
/**
 * Process e-commerce order data
 * Validate payment, update inventory, send confirmation email
 */
function processOrder(order, paymentMethod, inventory) \\\\{
  // Rich, contextual suggestions
\\\\}
# Use Copilot for code review assistance
# 1. Select code block
# 2. Ask Copilot to review for:
#    - Security vulnerabilities
#    - Performance issues
#    - Code style consistency
#    - Potential bugs

# Example review prompts
/explain potential security issues in this code
/fix performance bottlenecks in this function
/optimize this database query
// Generate comprehensive test suites
// 1. Select function or class
// 2. Use /tests command
// 3. Copilot generates:
//    - Unit tests
//    - Edge cases
//    - Mock implementations
//    - Test data

// Example test generation
describe('UserService', () => \\\\{
  // Copilot suggests complete test suite
  it('should authenticate valid user', () => \\\\{
    // Test implementation suggestions
  \\\\});
\\\\});
\\\\{
  "github.copilot.enable": \\\\{
    "*": true,
    "yaml": false,
    "plaintext": false
  \\\\},
  "github.copilot.advanced": \\\\{
    "secret_key": "example",
    "length": 500
  \\\\},
  "github.copilot.chat.localeOverride": "en"
\\\\}
-- Copilot configuration
vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true
vim.g.copilot_tab_fallback = ""

-- Custom keybindings
vim.api.nvim_set_keymap("i", "<C-J>", 'copilot#Accept("<CR>")', \\\\{ silent = true, expr = true \\\\})
vim.api.nvim_set_keymap("i", "<C-H>", 'copilot#Previous()', \\\\{ silent = true, expr = true \\\\})
vim.api.nvim_set_keymap("i", "<C-L>", 'copilot#Next()', \\\\{ silent = true, expr = true \\\\})
# Copilot not working
:Copilot status
# Check authentication and network connectivity

# No suggestions appearing
# 1. Check file type is supported
# 2. Verify Copilot is enabled for file type
# 3. Restart IDE
# 4. Check subscription status

# Suggestions are poor quality
# 1. Provide more context in comments
# 2. Use descriptive variable names
# 3. Include type annotations
# 4. Add relevant imports and dependencies
# Reduce latency
# 1. Use local caching
# 2. Optimize network connection
# 3. Close unnecessary files
# 4. Restart IDE periodically

# Improve suggestion quality
# 1. Keep related files open
# 2. Use consistent coding style
# 3. Include comprehensive comments
# 4. Maintain clean project structure
# Organization management
# 1. Admin controls for user access
# 2. Usage analytics and reporting
# 3. Policy enforcement
# 4. Audit logs

# Security features
# 1. Code suggestion filtering
# 2. IP allowlisting
# 3. SAML SSO integration
# 4. Data residency controls
# Data handling
# 1. Code snippets not stored by default
# 2. Telemetry can be disabled
# 3. On-premises deployment options
# 4. GDPR and SOC 2 compliance

# Content filtering
# 1. Block suggestions matching public code
# 2. Filter sensitive patterns
# 3. Customize blocked content
# 4. Audit suggestion sources
# GitHub Actions with Copilot
name: Copilot Code Review
on: [pull_request]

jobs:
  copilot-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Copilot Code Analysis
        uses: github/copilot-cli-action@v1
        with:
          command: 'review'
          files: '**/*.js'
// Automated documentation generation
// 1. Select functions without documentation
// 2. Use Copilot to generate JSDoc comments
// 3. Review and commit documentation updates

// Code migration assistance
// 1. Provide target framework context
// 2. Use Copilot to suggest migration patterns
// 3. Iteratively convert code sections
// 4. Test and validate migrations