Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 071-GitHubCopilot/Coach/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 071-GitHubCopilot/Coach/Solution-07.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
91 changes: 91 additions & 0 deletions 071-GitHubCopilot/Coach/Solution-08.md
Original file line number Diff line number Diff line change
@@ -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
95 changes: 95 additions & 0 deletions 071-GitHubCopilot/Coach/Solution-09.md
Original file line number Diff line number Diff line change
@@ -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 <user>/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 <user>/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.
5 changes: 5 additions & 0 deletions 071-GitHubCopilot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 071-GitHubCopilot/Student/Challenge-07.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
82 changes: 82 additions & 0 deletions 071-GitHubCopilot/Student/Challenge-08.md
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading