From b08e9d3454d286f31834e78f8ee6ad534787c929 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 23:55:07 +0000 Subject: [PATCH 1/2] Initial plan From 8df9f195cf598acdb7f5c171fe169388570c39ee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 23:59:11 +0000 Subject: [PATCH 2/2] feat: add Challenge-08 and Challenge-09 for GitHub Copilot CLI exercises Co-authored-by: tcardosoMSFT <17726346+tcardosoMSFT@users.noreply.github.com> --- 071-GitHubCopilot/Coach/README.md | 6 ++ 071-GitHubCopilot/Coach/Solution-07.md | 2 +- 071-GitHubCopilot/Coach/Solution-08.md | 91 ++++++++++++++++++++++ 071-GitHubCopilot/Coach/Solution-09.md | 95 +++++++++++++++++++++++ 071-GitHubCopilot/README.md | 5 ++ 071-GitHubCopilot/Student/Challenge-07.md | 2 +- 071-GitHubCopilot/Student/Challenge-08.md | 82 +++++++++++++++++++ 071-GitHubCopilot/Student/Challenge-09.md | 85 ++++++++++++++++++++ 8 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 071-GitHubCopilot/Coach/Solution-08.md create mode 100644 071-GitHubCopilot/Coach/Solution-09.md create mode 100644 071-GitHubCopilot/Student/Challenge-08.md create mode 100644 071-GitHubCopilot/Student/Challenge-09.md diff --git a/071-GitHubCopilot/Coach/README.md b/071-GitHubCopilot/Coach/README.md index 95a7360815..55deafb9d2 100644 --- a/071-GitHubCopilot/Coach/README.md +++ b/071-GitHubCopilot/Coach/README.md @@ -24,6 +24,10 @@ Welcome to the coach's guide for the GitHub Copilot What The Hack. Here you will - Generate test cases and documentation with the help of GitHub Copilot. - Challenge 07: **[Debugging and Code Optimization with Copilot](./Solution-07.md)** - Use GitHub Copilot for debugging and optimizing your code effectively. +- Challenge 08: **[Getting Started with GitHub Copilot in the CLI](./Solution-08.md)** + - Use `gh copilot suggest` and `gh copilot explain` to work with Copilot directly from your terminal. +- Challenge 09: **[Automating DevOps Workflows with GitHub Copilot CLI](./Solution-09.md)** + - Automate an end-to-end DevOps workflow using GitHub Copilot CLI. ## Coach Prerequisites @@ -50,6 +54,8 @@ This hack is intended to be completed in 1 day in 4.5 hours. - Challenge 5 (30 mins) - Challenge 6 (45 mins) - Challenge 7 (30 mins) + - Challenge 8 (45 mins) + - Challenge 9 (60 mins) ## Repository Contents diff --git a/071-GitHubCopilot/Coach/Solution-07.md b/071-GitHubCopilot/Coach/Solution-07.md index 37db34f62d..bec2575781 100644 --- a/071-GitHubCopilot/Coach/Solution-07.md +++ b/071-GitHubCopilot/Coach/Solution-07.md @@ -1,6 +1,6 @@ # Challenge 07 - Debugging and Code Optimization with Copilot - Coach's Guide -[< Previous Solution](./Solution-06.md) - **[Home](./README.md)** +[< Previous Solution](./Solution-06.md) - **[Home](./README.md)** - [Next Solution >](./Solution-08.md) ## Notes & Guidance diff --git a/071-GitHubCopilot/Coach/Solution-08.md b/071-GitHubCopilot/Coach/Solution-08.md new file mode 100644 index 0000000000..919749c486 --- /dev/null +++ b/071-GitHubCopilot/Coach/Solution-08.md @@ -0,0 +1,91 @@ +# Challenge 08 - Getting Started with GitHub Copilot in the CLI - Coach's Guide + +[< Previous Solution](./Solution-07.md) - **[Home](./README.md)** - [Next Solution >](./Solution-09.md) + +## Notes & Guidance + +This challenge introduces students to the `gh copilot` CLI extension. It is intentionally exploratory—there is no single correct answer. The goal is to get students comfortable using natural language at the terminal and to help them understand how Copilot CLI fits into their day-to-day workflow. + +### Key Concepts to Explain Before the Challenge + +**GitHub Copilot CLI (`gh copilot`):** +- Distributed as a `gh` extension: `gh extension install github/gh-copilot` +- Two primary commands: + - `gh copilot suggest` – generates a shell, `git`, or `gh` command from a plain-English description + - `gh copilot explain` – explains what a given command does in plain English +- Copilot CLI supports an interactive **refine** flow that lets students iterate on a suggestion without re-typing the full prompt +- Requires GitHub CLI (`gh`) to be installed and authenticated + +### Installation + +Students must have: +1. [GitHub CLI](https://cli.github.com/) installed (`gh --version` to verify) +2. Authenticated via `gh auth login` +3. Extension installed: `gh extension install github/gh-copilot` +4. A GitHub Copilot subscription (Individual, Business, or Enterprise) + +Common install issue: if `gh auth status` shows the user is authenticated but `gh copilot` returns a permissions error, they may need to refresh the token scope: +```bash +gh auth refresh -s read:user +``` + +### Guidance for `gh copilot explain` + +Students should try a variety of command types. Example prompts and expected topics to discuss: + +| Command | What students should notice | +|---|---| +| `git rebase -i HEAD~3` | Interactive rebase; squashing/editing commits | +| `find . -name "*.log" -mtime +7 -delete` | Deleting old log files; `-mtime` flag | +| `gh pr list --state open --label bug` | Listing PRs filtered by label via `gh` CLI | +| `awk '{print $1}' access.log \| sort \| uniq -c \| sort -rn \| head -10` | Top IP addresses in a log file | + +Encourage students to pick commands from their own projects—real-world context makes the explanations more meaningful. + +### Guidance for `gh copilot suggest` + +Remind students to select the right command type at the interactive prompt (shell, git, or gh). If they are unsure, `shell` works as a safe default. + +Example prompts and expected suggestions: + +| Prompt | Expected suggestion (approximate) | +|---|---| +| "list all git branches sorted by last commit date" | `git branch --sort=-committerdate` | +| "create a GitHub issue titled 'Add dark mode' in my repo" | `gh issue create --title "Add dark mode" --body "..."` | +| "find all files larger than 10 MB in the current directory" | `find . -size +10M -type f` | +| "delete all local git branches that have been merged" | `git branch --merged \| grep -v main \| xargs git branch -d` | +| "show the last 5 commits with their author and date" | `git log --oneline --format="%h %an %ad %s" -5` | + +### The Refine Flow + +After Copilot returns a suggestion, the interactive prompt offers: +- **Copy command to clipboard** – pastes into the terminal +- **Explain command** – inline explanation +- **Revise command** – re-prompts with the original context; students can type corrections +- **Rate response** – optional feedback + +Make sure students use **Revise** at least once so they experience iterative refinement. + +### Common Issues + +| Issue | Resolution | +|---|---| +| `gh copilot: command not found` | Run `gh extension install github/gh-copilot` | +| `Error: your token does not have the required scopes` | Run `gh auth refresh -s read:user` | +| Copilot returns generic or incorrect commands | Prompt is likely too vague—encourage students to add more context | +| Interactive prompt does not appear | Ensure terminal supports interactive mode; avoid piping stdout | + +### Success Criteria Validation + +- **Installation**: `gh copilot --version` should return a version string. +- **explain**: Student should show screenshots or live demo of at least three `explain` invocations with a brief verbal summary of each. +- **suggest**: Student should show five or more suggestions and demonstrate that they read and understood each before running it. +- **Refine**: Student should show the revised prompt and the updated suggestion side by side. +- **Reflection**: Accept any genuine scenario—this is a discussion, not a graded answer. + +### Estimated Time + +This challenge typically takes 30–45 minutes: +- 10 minutes: Installation and authentication +- 15 minutes: Exploring `explain` and `suggest` +- 10 minutes: Refining suggestions and reflection diff --git a/071-GitHubCopilot/Coach/Solution-09.md b/071-GitHubCopilot/Coach/Solution-09.md new file mode 100644 index 0000000000..8605e65d30 --- /dev/null +++ b/071-GitHubCopilot/Coach/Solution-09.md @@ -0,0 +1,95 @@ +# Challenge 09 - Automating DevOps Workflows with GitHub Copilot CLI - Coach's Guide + +[< Previous Solution](./Solution-08.md) - **[Home](./README.md)** + +## Notes & Guidance + +This challenge builds on Challenge 08 by putting `gh copilot suggest` to work in a structured, end-to-end DevOps workflow. Students should leave with a concrete understanding of how Copilot CLI accelerates everyday Git/GitHub operations and where its current limitations lie. + +### Key Concepts to Reinforce + +- Copilot CLI is most effective when prompts are **specific and scoped** to a single action. +- The `--shell`, `--git`, and `--gh` flags (or the interactive type selection) steer Copilot toward the right command family. +- Always review a suggested command before executing it—especially commands that delete, push, or modify remote resources. + +### Step-by-Step Guidance + +#### Step 1 – Repository and Branch Management + +Example prompts and expected outputs: + +| Prompt | Expected command | +|---|---| +| "create a new public GitHub repository called copilot-cli-demo with a README" | `gh repo create copilot-cli-demo --public --add-readme` | +| "clone the repository copilot-cli-demo" | `gh repo clone /copilot-cli-demo` | +| "create a new branch called feature/hello-world and switch to it" | `git checkout -b feature/hello-world` | +| "create a shell script that prints Hello Copilot CLI" | `echo 'echo "Hello, Copilot CLI!"' > hello.sh && chmod +x hello.sh` | +| "stage all changes, commit with message 'Add hello world script', and push feature branch" | `git add . && git commit -m "Add hello world script" && git push -u origin feature/hello-world` | + +#### Step 2 – Pull Request Automation + +| Prompt | Expected command | +|---|---| +| "open a pull request from feature/hello-world to main with title 'Add hello world script'" | `gh pr create --base main --head feature/hello-world --title "Add hello world script" --body "Adds a simple hello world shell script"` | +| "list all open pull requests in this repository" | `gh pr list --state open` | +| "merge the open pull request using squash merge" | `gh pr merge --squash` | + +**Note**: Students may need to enable squash merging in the repository settings if it is not already on. + +#### Step 3 – Release Management + +| Prompt | Expected command | +|---|---| +| "create a git tag v1.0.0 on the latest commit" | `git tag v1.0.0` | +| "push the tag v1.0.0 to GitHub" | `git push origin v1.0.0` | +| "create a GitHub release for v1.0.0 with auto-generated release notes" | `gh release create v1.0.0 --generate-notes` | + +#### Step 4 – Operational Tasks + +| Prompt | Expected command | +|---|---| +| "find the 10 largest files in the current directory" | `find . -type f -printf '%s %p\n' \| sort -rn \| head -10` (Linux) or `du -sh * \| sort -rh \| head -10` | +| "search git history for commits mentioning 'fix'" | `git log --oneline --grep="fix"` | +| "compress the current directory into a tar.gz archive" | `tar -czf ../copilot-cli-demo.tar.gz .` | + +### Common Issues + +| Issue | Resolution | +|---|---| +| `gh repo create` fails with permissions error | Ensure `gh auth login` has been run and the token has `repo` scope | +| PR creation fails because branches are not on remote | Student forgot to push the feature branch before creating the PR | +| `gh release create` returns 404 | The tag was not pushed; run `git push origin v1.0.0` first | +| Suggested `find` command uses Linux-only flags on macOS | Prompt refinement: add "on macOS" to the natural-language request, or use `du` variant | + +### Success Criteria Validation + +- **Repository**: Verify with `gh repo view /copilot-cli-demo` or by browsing to the GitHub URL. +- **PR workflow**: Show `gh pr list` output and the merged PR on GitHub. +- **Release**: Show `gh release view v1.0.0` or the Releases page on GitHub. +- **Operational tasks**: Output from the commands is sufficient—files do not need to be large for the task to succeed. +- **explain usage**: Student should show the `gh copilot explain` output for at least one command they found unfamiliar. +- **Reflection**: Encourage honest discussion—Copilot CLI does not always get the platform-specific flags right; that is a valid and valuable finding. + +### Cleanup (Optional) + +To avoid leaving demo repositories behind, students can delete the repository when finished: + +```bash +gh repo delete copilot-cli-demo --yes +``` + +Suggest students use `gh copilot suggest` to generate this cleanup command as well! + +### Estimated Time + +This challenge typically takes 45–60 minutes: +- 15 minutes: Repository setup and branch management +- 15 minutes: PR automation and release management +- 10 minutes: Operational tasks +- 10 minutes: Reflection and discussion + +### Additional Discussion Points + +- Discuss how Copilot CLI differs from Copilot in the IDE—same underlying model, different interaction surface. +- Ask students: "Could you build a reusable shell script that wraps these `gh` commands to create a project template?" This sets up the Advanced Challenge. +- Point out that `gh copilot suggest` learns from the **type** selection (shell vs. git vs. gh) to provide better scoped suggestions—emphasising command type selection is a useful best practice. diff --git a/071-GitHubCopilot/README.md b/071-GitHubCopilot/README.md index 8db4e90bd8..f7a8b7b538 100644 --- a/071-GitHubCopilot/README.md +++ b/071-GitHubCopilot/README.md @@ -34,11 +34,16 @@ This GitHub Copilot What The Hack will help you learn how to do the following wi - Generate test cases and documentation with the help of GitHub Copilot. - Challenge 07: **[Debugging and Code Optimization with Copilot](Student/Challenge-07.md)** - Use GitHub Copilot for debugging and optimizing your code effectively. +- Challenge 08: **[Getting Started with GitHub Copilot in the CLI](Student/Challenge-08.md)** + - Use `gh copilot suggest` and `gh copilot explain` to work with Copilot directly from your terminal. +- Challenge 09: **[Automating DevOps Workflows with GitHub Copilot CLI](Student/Challenge-09.md)** + - Automate an end-to-end DevOps workflow using GitHub Copilot CLI. ## Prerequisites - A GitHub account with GitHub Copilot subscription or Copilot Trial - Visual Studio Code with GitHub Copilot extension installed +- GitHub CLI (`gh`) installed and authenticated (required for Challenges 08 and 09) - Basic understanding of software development and version control systems ## Contributors diff --git a/071-GitHubCopilot/Student/Challenge-07.md b/071-GitHubCopilot/Student/Challenge-07.md index 80abe79baf..613b74ef06 100644 --- a/071-GitHubCopilot/Student/Challenge-07.md +++ b/071-GitHubCopilot/Student/Challenge-07.md @@ -1,6 +1,6 @@ # Challenge 07 - Debugging and Code Optimization with Copilot -[< Previous Challenge](./Challenge-06.md) - **[Home](../README.md)** +[< Previous Challenge](./Challenge-06.md) - **[Home](../README.md)** - [Next Challenge >](./Challenge-08.md) ## Introduction In this final challenge, you'll harness the power of GitHub Copilot to identify and resolve security vulnerabilities in a pre-written code snippet. You will also optimize your code, refining its performance and maintainability based on the intelligent suggestions provided by Copilot. This challenge is an opportunity to deepen your understanding of how Copilot can be an integral part of your debugging and code optimization processes. diff --git a/071-GitHubCopilot/Student/Challenge-08.md b/071-GitHubCopilot/Student/Challenge-08.md new file mode 100644 index 0000000000..0c9b861c0a --- /dev/null +++ b/071-GitHubCopilot/Student/Challenge-08.md @@ -0,0 +1,82 @@ +# Challenge 08 - Getting Started with GitHub Copilot in the CLI + +[< Previous Challenge](./Challenge-07.md) - **[Home](../README.md)** - [Next Challenge >](./Challenge-09.md) + +## Introduction + +GitHub Copilot is not limited to your IDE. With the **GitHub Copilot CLI** extension (`gh copilot`), you can bring the power of Copilot directly into your terminal. Whether you need to recall the exact syntax for a complex command, understand what an unfamiliar shell script does, or generate commands from natural language, Copilot CLI has you covered. + +In this challenge, you will install the `gh copilot` extension and explore its two core commands: +- `gh copilot suggest` – generate shell, `git`, or `gh` commands from a plain-English description +- `gh copilot explain` – get a plain-English explanation of any command + +## Description + +### Step 1 – Install the GitHub Copilot CLI Extension + +The Copilot CLI extension is distributed as a GitHub CLI (`gh`) extension. Make sure the [GitHub CLI](https://cli.github.com/) is installed and that you are authenticated, then run: + +```bash +gh extension install github/gh-copilot +``` + +Verify the installation: + +```bash +gh copilot --version +``` + +### Step 2 – Explore `gh copilot explain` + +Pick a shell command you find confusing or have never used before and ask Copilot to explain it. For example: + +```bash +gh copilot explain "git rebase -i HEAD~3" +``` + +Try at least **three** different commands across different categories (e.g., `git`, Linux shell, `gh` CLI). + +### Step 3 – Explore `gh copilot suggest` + +Use natural language to ask Copilot to generate a command for you. For example: + +```bash +gh copilot suggest "list all git branches sorted by the date of their last commit" +``` + +Experiment with at least **five** different requests, covering: +- A `git` operation +- A `gh` CLI operation (e.g., creating an issue, cloning a repo) +- A generic shell operation (e.g., file manipulation, process management) +- A multi-step task that results in a script or pipeline + +### Step 4 – Refine and Revise + +After Copilot provides a suggestion, explore the **refine** option that lets you iterate on the suggestion. Modify your request and observe how the output changes. + +## Success Criteria + +You will have successfully completed this challenge when you: + +- Demonstrate that `gh copilot` is installed and accessible from the terminal +- Show `gh copilot explain` output for at least three different commands and describe what Copilot told you +- Show `gh copilot suggest` output for at least five different natural-language requests +- Demonstrate using the **refine** option to improve or adjust a suggestion +- Explain a scenario from your own day-to-day work where `gh copilot suggest` or `gh copilot explain` would save you time + +## Learning Resources + +- [GitHub Copilot in the CLI Documentation](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-in-the-command-line) +- [GitHub CLI Documentation](https://cli.github.com/manual/) +- [GitHub Copilot Documentation](https://docs.github.com/en/copilot) + +## Tips + +- If Copilot's first suggestion is not quite right, use the **refine** option instead of starting over—iterative refinement often yields better results than a single detailed prompt. +- You can alias `gh copilot suggest` and `gh copilot explain` to shorter commands in your shell profile to speed up your workflow. +- Try asking Copilot CLI to explain commands from scripts you have inherited—it is a great way to onboard onto unfamiliar codebases. + +## Advanced Challenges (Optional) + +- Configure shell aliases so that `??` runs `gh copilot suggest` and `git?` runs `gh copilot explain "git ..."` for a faster CLI workflow. +- Ask Copilot CLI to help you write a Bash one-liner that automates a repetitive task in your current project. diff --git a/071-GitHubCopilot/Student/Challenge-09.md b/071-GitHubCopilot/Student/Challenge-09.md new file mode 100644 index 0000000000..507d2487aa --- /dev/null +++ b/071-GitHubCopilot/Student/Challenge-09.md @@ -0,0 +1,85 @@ +# Challenge 09 - Automating DevOps Workflows with GitHub Copilot CLI + +[< Previous Challenge](./Challenge-08.md) - **[Home](../README.md)** + +## Introduction + +Now that you are comfortable with the basics of GitHub Copilot CLI, it is time to put it to work in a realistic DevOps scenario. In this challenge you will use `gh copilot suggest` to automate an end-to-end mini DevOps workflow: from setting up a repository and managing branches to running a CI-like check, creating releases, and cleaning up resources—all driven by natural-language prompts from the terminal. + +The goal is not just to generate commands, but to experience how Copilot CLI can act as a **productivity multiplier** across every stage of a developer's day. + +## Description + +### Scenario + +You have just joined a new team and need to set up a project repository, manage its branches, automate a basic quality check, and prepare a release—all from the command line and all with the help of Copilot CLI. You will use a combination of `gh copilot suggest` and `gh copilot explain` to complete each step. + +### Step 1 – Repository and Branch Management + +Use `gh copilot suggest` to generate commands that: + +1. Create a new **public** GitHub repository called `copilot-cli-demo` with a README. +2. Clone the repository locally. +3. Create a feature branch named `feature/hello-world`. +4. Add a simple `hello.sh` script that prints `Hello, Copilot CLI!`. +5. Stage, commit (with a meaningful message), and push the feature branch. + +### Step 2 – Pull Request Automation + +Use `gh copilot suggest` to generate `gh` CLI commands that: + +1. Open a pull request from `feature/hello-world` to `main` with a descriptive title and body. +2. List open pull requests in the repository. +3. Merge the pull request using the **squash** strategy. + +### Step 3 – Release Management + +Use `gh copilot suggest` to generate commands that: + +1. Create a git tag `v1.0.0` on the latest commit of `main`. +2. Push the tag to GitHub. +3. Create a GitHub release for `v1.0.0` with auto-generated release notes. + +### Step 4 – Operational Tasks + +Use `gh copilot suggest` or `gh copilot explain` to: + +1. Find and display the **10 largest files** in the repository. +2. Search the repository's commit history for commits that mention the word `fix`. +3. Archive and compress the repository directory into a `.tar.gz` file. + +### Step 5 – Reflection + +For each step above, note: +- The natural-language prompt you used with `gh copilot suggest`. +- Whether you needed to **refine** the prompt before executing the command. +- Any commands Copilot suggested that you did not recognise—use `gh copilot explain` to understand them. + +## Success Criteria + +You will have successfully completed this challenge when you: + +- Demonstrate a GitHub repository created, cloned, and managed entirely using commands generated by `gh copilot suggest` +- Show a pull request opened, listed, and merged via `gh` CLI commands suggested by Copilot +- Show a tagged GitHub release with auto-generated release notes created from the terminal +- Complete at least two operational tasks (Step 4) using Copilot-suggested commands +- Explain at least one command you did not initially recognise using `gh copilot explain` +- Summarise what worked well and any limitations you discovered when using Copilot CLI for DevOps tasks + +## Learning Resources + +- [GitHub Copilot in the CLI Documentation](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-in-the-command-line) +- [GitHub CLI Manual](https://cli.github.com/manual/) +- [Managing Releases in a Repository](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) +- [GitHub Copilot Documentation](https://docs.github.com/en/copilot) + +## Tips + +- Break complex tasks into smaller, focused prompts—Copilot CLI performs best when each prompt targets a single action. +- When a suggested command includes flags you are not sure about, run `gh copilot explain` on the full command before executing it. +- Use the `--shell` flag with `gh copilot suggest` (or select the appropriate command type at the interactive prompt) to specify whether you want a shell, `git`, or `gh` command. + +## Advanced Challenges (Optional) + +- Write a **Bash script** that chains together several of the commands generated in this challenge to create a fully automated "create, commit, PR, merge, release" pipeline using `gh copilot suggest` for each step. +- Set up a GitHub Actions workflow that runs `shellcheck` against `hello.sh` and use `gh copilot suggest` to generate the workflow YAML from a natural-language description.