Workflows Intermediate
This lesson covers practical, real-world workflows where GitHub Copilot CLI shines. Each section provides step-by-step examples you can adapt to your own work.
Finding the Right Command Workflow
The most common Copilot CLI workflow is a three-step pattern: describe, review, execute.
- Describe what you want — Use natural language to describe your goal. Be as specific as possible.
-
Review the suggestion — Read the suggested command carefully. Use
gh copilot explainif any part is unclear. - Execute or refine — Run the command directly, copy it, or choose "Revise command" to iterate.
# Step 1: Describe $ gh copilot suggest "find all TODO comments in JavaScript files" # Step 2: Review the suggestion # Suggestion: grep -rn "TODO" --include="*.js" . # Step 3a: If unclear, explain it $ gh copilot explain "grep -rn 'TODO' --include='*.js' ." # Step 3b: Execute or revise # Choose "Execute command" or "Revise command" from the menu
Git Operations with Copilot CLI
Git has hundreds of commands and flags. Copilot CLI is perfect for finding the exact git command you need.
Branching Workflow
# Create and switch to a new feature branch $ gh copilot suggest -t git "create a new branch called feature/auth from main" # Suggestion: git checkout -b feature/auth main # See all branches with last commit date $ gh copilot suggest -t git "list all branches sorted by last commit date" # Suggestion: git branch -a --sort=-committerdate --format='%(committerdate:short) %(refname:short)' # Clean up stale remote tracking branches $ gh copilot suggest -t git "remove remote tracking branches that no longer exist on remote" # Suggestion: git fetch --prune
Commit History Workflow
# Find when a line was introduced $ gh copilot suggest -t git "find which commit introduced the text 'API_KEY' in config.js" # Suggestion: git log -S 'API_KEY' -- config.js # View changes between two branches $ gh copilot suggest -t git "show all files changed between main and feature branch" # Suggestion: git diff --name-only main...feature # Undo a specific commit without losing history $ gh copilot suggest -t git "revert commit abc1234 without automatically committing" # Suggestion: git revert abc1234 --no-commit
System Administration Tasks
System administration involves commands that are often hard to remember. Copilot CLI makes these accessible.
User and Permission Management
# Find files with world-writable permissions $ gh copilot suggest -t shell "find all world-writable files in /var" # Suggestion: find /var -type f -perm -002 # Check disk space on all mounted volumes $ gh copilot suggest -t shell "show disk usage in human readable format for all partitions" # Suggestion: df -h # Monitor system resources $ gh copilot suggest -t shell "show top 10 processes by memory usage" # Suggestion: ps aux --sort=-%mem | head -11
Service Management
# Check if a service is running $ gh copilot suggest -t shell "check if nginx is running and show its status" # Suggestion: systemctl status nginx # View recent log entries $ gh copilot suggest -t shell "show the last 50 lines of syslog and follow new entries" # Suggestion: tail -n 50 -f /var/log/syslog # Cron jobs $ gh copilot suggest -t shell "add a cron job that runs a backup script every day at 2am" # Suggestion: (crontab -l; echo "0 2 * * * /path/to/backup.sh") | crontab -
DevOps and CI/CD Commands
Copilot CLI is particularly useful for Docker, Kubernetes, and CI/CD operations where command syntax is complex.
Docker Workflow
# Clean up unused Docker resources $ gh copilot suggest -t shell "remove all stopped containers, unused networks, and dangling images" # Suggestion: docker system prune -f # View logs of a specific container $ gh copilot suggest -t shell "show logs from the last hour for the web container and follow" # Suggestion: docker logs --since 1h -f web # Build and tag an image $ gh copilot suggest -t shell "build docker image tagged myapp:latest from current directory" # Suggestion: docker build -t myapp:latest .
Kubernetes Workflow
# Check pod status $ gh copilot suggest -t shell "list all pods in the production namespace with their status" # Suggestion: kubectl get pods -n production -o wide # Restart a deployment $ gh copilot suggest -t shell "restart all pods in the api deployment" # Suggestion: kubectl rollout restart deployment/api # Port forwarding $ gh copilot suggest -t shell "forward local port 8080 to port 80 on the nginx pod" # Suggestion: kubectl port-forward pod/nginx 8080:80
GitHub Actions Workflow
# Check CI status $ gh copilot suggest -t gh "show the status of the last CI run on the current branch" # Suggestion: gh run list --branch $(git branch --show-current) --limit 1 # Re-run a failed workflow $ gh copilot suggest -t gh "re-run only the failed jobs from the latest workflow run" # Suggestion: gh run rerun --failed # View workflow logs $ gh copilot suggest -t gh "download logs from the latest workflow run" # Suggestion: gh run view --log
Database Operations
Database commands often have complex syntax. Copilot CLI can help you construct the right queries and connection strings.
# PostgreSQL backup $ gh copilot suggest -t shell "backup a PostgreSQL database called mydb to a compressed file" # Suggestion: pg_dump mydb | gzip > mydb_backup.sql.gz # MySQL query from command line $ gh copilot suggest -t shell "connect to MySQL and show the size of all databases" # Suggestion: mysql -u root -p -e "SELECT table_schema, ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.tables GROUP BY table_schema;" # Redis operations $ gh copilot suggest -t shell "flush all keys in Redis database 0" # Suggestion: redis-cli -n 0 FLUSHDB # MongoDB export $ gh copilot suggest -t shell "export a MongoDB collection called users to JSON" # Suggestion: mongoexport --db mydb --collection users --out users.json
File Management
From bulk renaming to finding duplicates, file management tasks are a natural fit for Copilot CLI.
# Bulk rename files $ gh copilot suggest -t shell "rename all .jpeg files to .jpg in current directory" # Suggestion: rename 's/\.jpeg$/.jpg/' *.jpeg # Find and remove empty directories $ gh copilot suggest -t shell "find and delete all empty directories recursively" # Suggestion: find . -type d -empty -delete # Sync directories $ gh copilot suggest -t shell "sync contents of src to dest, deleting files in dest that are not in src" # Suggestion: rsync -av --delete src/ dest/ # File permissions $ gh copilot suggest -t shell "make all shell scripts in the project executable" # Suggestion: find . -name '*.sh' -exec chmod +x {} + # Disk usage analysis $ gh copilot suggest -t shell "show the 10 largest files in the home directory" # Suggestion: find ~ -type f -exec du -h {} + | sort -rh | head -10
Network Troubleshooting
Network commands are notoriously hard to remember. Copilot CLI makes network diagnostics much more accessible.
# Check open ports $ gh copilot suggest -t shell "list all open TCP ports and the process using them" # Suggestion: ss -tlnp # DNS lookup $ gh copilot suggest -t shell "look up all DNS records for example.com" # Suggestion: dig example.com ANY +noall +answer # Test API endpoints $ gh copilot suggest -t shell "send a POST request with JSON body to an API endpoint" # Suggestion: curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/endpoint # SSL certificate check $ gh copilot suggest -t shell "check the SSL certificate expiration date for example.com" # Suggestion: echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates # Bandwidth testing $ gh copilot suggest -t shell "monitor network traffic on eth0 interface in real time" # Suggestion: iftop -i eth0
ss is Linux-specific, while macOS uses lsof or netstat for similar purposes.
Try It Yourself
Practice these workflows:
- Use Copilot CLI to find a git command that shows all commits touching a specific file
- Ask for a Docker command to view the resource usage of all running containers
- Get a command to search and replace text across all files in a directory
- Ask for a command to test if a specific port is open on a remote host
- Use
gh copilot explainon any suggested command you do not fully understand
Lilly Tech Systems