Skip to content

Exercise: Getting Started with GitHub Copilot #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
github-actions bot opened this issue Mar 24, 2025 · 7 comments
Open

Exercise: Getting Started with GitHub Copilot #1

github-actions bot opened this issue Mar 24, 2025 · 7 comments

Comments

@github-actions
Copy link
Contributor

Getting Started with GitHub Copilot

original github octocat

👋 Hey there david-juran! Welcome to your Skills exercise!

Welcome to the exciting world of GitHub Copilot! 🚀 In this exercise, you'll unlock the potential of this AI-powered coding assistant to accelerate your development process. Let's dive in and have some fun exploring the future of coding together! 💻✨

As you complete each step, I will respond in the comments to:

  • check your work and give feedback
  • share next steps
  • occasionally share tips
  • congratulate you when you finish!

Good luck and have fun!
- Mona

Copy link
Contributor Author

Step 1: Hello Copilot

Welcome to your "Getting Started with GitHub Copilot" exercise! 🤖

In this exercise, you will be using different GitHub Copilot features to work on a website that allows students of Mergington High School to sign up for extracurricular activities. 🎻 ⚽️ ♟️

screenshot of Mergington High School WebApp

What is GitHub Copilot?

copilot logo

GitHub Copilot is an AI coding assistant that helps you write code faster and with less effort, allowing you to focus more energy on problem solving and collaboration.

GitHub Copilot has been proven to increase developer productivity and accelerate the pace of software development. For more information, see Research: quantifying GitHub Copilot’s impact on developer productivity and happiness in the GitHub blog.

Your most common interactions will likely be:

  • Inline suggestions: As you type, Copilot uses the nearby context to suggest code directly in your editor. This will be a familiar interaction if you have used code completion tools like Intellisense, except that the completions may be entire functions.
  • Copilot Chat: A dedicated chat panel that lets you ask coding related questions. This will feel familiar if you have used online AI assistant chats. The big difference however, is that your project files will provide automatic context to provide tailored responses.
  • Copilot Edits: Similar to Copilot Chat, but less conversational and more big picture or goal oriented.

Tip

You can learn more about current and upcoming features in the GitHub Copilot Features documentation. You can also select different models and make your own extensions, but that's for a different lesson!

How can I use GitHub Copilot?

As you work, you'll find GitHub Copilot can help out in several places across the website and in your favorite coding environments such as VS Code, Jet Brains, and Xcode! For today's coding though, we will practice with VS Code in a preconfigured development environment known as Codespace.

⌨️ Activity: Get a project intro from Copilot Chat

Let's start up our development environment, use copilot to learn a bit about the project, and then give it a test run.

  1. Right-click the below button to open the Create Codespace page in a new tab. Use the default configuration.

    Open in GitHub Codespaces

  2. Confirm the Repository field is your copy of the exercise, not the original, then click the green Create Codespace button.

    • ✅ Your copy: /david-juran/skills-getting-started-with-github-copilot
    • ❌ Original: /skills/getting-started-with-github-copilot
  3. Wait a moment for Visual Studio Code to load in your browser.

  4. In the left sidebar, click the extensions tab and verify that the GitHub Copilot and Python extensions are installed and enabled.

    copilot extension for VS Code python extension for VS Code
  5. At the top of VS Code, locate and click the Copilot icon to open a Copilot Chat panel.

    image
  6. If this is your first, time using GitHub Copilot, you will have to accept the usage terms to continue.

  7. Enter the below prompt to ask Copilot to introduce you to the project.

    Prompt

    @workspace Please briefly explain the structure of this project.
    What should I do to run it?
    

    Note: It is not necesesary to follow Copilot's recommended instructions. We have already prepared the environment for you.

  8. Now that we know a bit more about the project, let's actually try running it! In the left sidebar, select the Run and Debug tab and then press the Start Debugging icon.

    image
  9. We want to see our webpage running in a browser, so let's find the url and port. If it isn't visible, expand the lower panel and select the Ports tab.

  10. In the list, find port 8000 and the related link. Hover over the link and select the Open in browser icon.

    image

⌨️ Activity: Use Copilot to help remember a terminal command 🙋

Great work! Now that we are familiar with the app and we know it works, let's ask copilot for help starting a branch so we can do some customizing.

  1. If not already there, return to VS Code.

  2. In the bottom panel, select the Terminal tab. On the right side, click the plus + sign to create a new terminal window.

    Note: This will avoid stopping the existing debug session that is hosting our web application service.

  3. Within the new terminal window, right click and select Copilot then Terminal Inline Chat. Alternately, you can use the keyboard shortcut Ctrl + I (windows) or Cmd + I (mac).

  4. Let's ask Copilot to help us remember a command we have forgotten: creating a branch and publishing it

    Prompt

    Hey copilot, how can I create and publish a new Git branch?
    

    Tip: This is a simple example, but Copilot is great at providing more tailored commands that might involve loops, pattern matching, file modification, and more! Don't be afraid to ask Copilot for a suggestion. Just remember it is a suggestion and you should always verify it first to be safe.

  5. Copilot probably gave us a command like the following. Rather than manually modify it, let's respond back to tell Copilot to use a particular name.

    git checkout -b {new_branch_name}
    git push -u origin {new_branch_name}

    Prompt

    Awesome! Thanks, Copilot! Let's use the
    branch name "accelerate-with-copilot".
    

    Tip: If Copilot doesn't give you quite what you want, you can always continue explaining what you need. Copilot will remember the conversation history for follow-up responses.

  6. Now that we are happy with the command, press the Run button to let Copilot run it for us. No need to copy and paste!

  7. After a moment, look in the VS Code lower status bar, on the left, to see the active branch. It should now say accelerate-with-copilot. If so, you are all done with this step!

  8. Now that your branch is pushed to GitHub, Mona should already be busy checking your work. Give her a moment and keep watch in the comments. You will see her respond with progress info and the next lesson.

Having trouble? 🤷

If you don't get feedback, here are some things to check:

  • Make sure your created the branch with the exact name accelerate-with-copilot. No prefixes or suffixes.
  • Make sure the branch was indeed published to your repository.

Copy link
Contributor Author

github-actions bot commented Mar 24, 2025

🎉🎉🎉 Nice work! Everything is perfect! 🎉🎉🎉
Preparing content for step 2! One moment... 🤓

Copy link
Contributor Author

Step 2: Getting work done with Copilot

In the previous step, GitHub Copilot was able to help us onboard to the project. That alone is a huge time saver, but now let's get some work done!

We recently learned there is a bug where students are registering for the same activities twice. That simply isn't acceptable, so let's get it fixed!

Unfortunately, we were given little information to solve this problem. So, let's enlist Copilot to help find the problem area and get a potential solution made.

But before we do that, let's learn a bit more about Copilot! 🧑‍🚀

How does Copilot work?

In short, you can think of Copilot like a very focused coworker. To be effective with them, you need to provide them background (context) and clear direction (prompts). Additionally, different people are better at different things because of their unique experiences (models).

  • How do we provide context?: In our coding environment, Copilot will automatically consider nearby code and open tabs. If you are using chat, you can also explicitly refer to files.

  • What model should we pick?: For our exercise, it shouldn't matter too much. Experimenting with different models is part of the fun! That's another lesson! 🤖

  • How do I make prompts?: Being explicit and clear helps Copilot do the best job. But unlike some traditional systems, you can always clarify your direction with followup prompts.

⌨️ Activity: Use Copilot to fix our registration bug 🐛

  1. Let's ask Copilot to suggest where our bug might be coming from. Open the Copilot Chat panel and ask the following.

    Prompt

    @workspace Students are able to register twice for an activity.
    Where could this bug be coming from?
    
  2. Now that we know the issue is in the src/appy.py file and the signup_for_activity method, let's follow Copilot's recommendation and go fix it (semi-manually). We'll start with a comment and let Copilot finish the correction.

    1. In VS Code, select the file Explorer tab to show the project files and open the src/app.py file.

    2. Scroll near the bottom of the file and find the signup_for_activity method.

    3. Find the comment line that describes adding a student. Above this is where it seems logical to do our registration check.

    4. Enter the below comment and press enter to go to the next line. After a moment, temporary shadow text will appear with a suggestion from Copilot! Nice! 🎉

      # Validate student is not already signed up
    5. Press Tab to accept Copilot's suggestion and convert the shadow text to code.

      Tip: If you would like to see other suggestions, instead of pressing Tab, hover over the shadow text suggestion and a toolbar will appear. Use the arrows to select other suggestions or the three dots ... and Open Completions Panel option to show all suggestions in a dedicated panel.

    Example Results

    Copilot is growing every day and may not always produce the same results. If you are unhappy with the suggestions, here is an example of a valid suggestion result we produced during the making of this exercise. You can use it to continue forward.

    @app.post("/activities/{activity_name}/signup")
    def signup_for_activity(activity_name: str, email: str):
       """Sign up a student for an activity"""
       # Validate activity exists
       if activity_name not in activities:
          raise HTTPException(status_code=404, detail="Activity not found")
    
       # Get the activity
       activity = activities[activity_name]
    
       # Validate student is not already signed up
       if email in activity["participants"]:
         raise HTTPException(status_code=400, detail="Student is already signed up")
    
       # Add student
       activity["participants"].append(email)
       return {"message": f"Signed up {email} for {activity_name}"}

⌨️ Activity: Let Copilot generate sample data 📋

In new project developments, it's often helpful to have some realistic looking fake data for testing. Copilot is excellent at this task, so let's add some more sample activities and introduce another way to interact with Copilot using Inline Chat

Inline Chat and the Copilot Chat panel are very similar tools, but with slightly different automatic context. As such, while Copilot Chat is good at explaining about the project, inline chat might feel more natural for asking about a particular line or function.

  1. If not already open, open the src/app.py file.

  2. Near the top (about line 23), find the activities variable, where our example extracurricular activies are configured.

  3. Open Copilot inline chat by right-clicking on any of the related lines and selecting Copilot and Editor Inline Chat.

    Tip: You can also use the keyboard command Ctrl + I (windows) or Cmd + I (mac).

  4. Enter the following prompt text and press enter or the Send and Dispatch button.

    Prompt

    Add 2 more sports related activities, 2 more artistic
    activities, and 2 more intellectual activities.
    
  5. After a moment, Copilot will directly start making changes to the code. The changes will be stylized differently to make any additions and removals easy to identify. Take a moment to inspect and then press the Accept button.

Example Results

Copilot is growing every day and may not always produce the same results. If you are unhappy with the suggestions, here is an example result we produced during the making of this exercise. You can use it to continue forward, if having trouble.

# In-memory activity database
activities = {
   "Chess Club": {
      "description": "Learn strategies and compete in chess tournaments",
      "schedule": "Fridays, 3:30 PM - 5:00 PM",
      "max_participants": 12,
      "participants": ["[email protected]", "[email protected]"]
   },
   "Programming Class": {
      "description": "Learn programming fundamentals and build software projects",
      "schedule": "Tuesdays and Thursdays, 3:30 PM - 4:30 PM",
      "max_participants": 20,
      "participants": ["[email protected]", "[email protected]"]
   },
   "Gym Class": {
      "description": "Physical education and sports activities",
      "schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
      "max_participants": 30,
      "participants": ["[email protected]", "[email protected]"]
   },
   "Basketball Team": {
      "description": "Competitive basketball training and games",
      "schedule": "Tuesdays and Thursdays, 4:00 PM - 6:00 PM",
      "max_participants": 15,
      "participants": []
   },
   "Swimming Club": {
      "description": "Swimming training and water sports",
      "schedule": "Mondays and Wednesdays, 3:30 PM - 5:00 PM",
      "max_participants": 20,
      "participants": []
   },
   "Art Studio": {
      "description": "Express creativity through painting and drawing",
      "schedule": "Wednesdays, 3:30 PM - 5:00 PM",
      "max_participants": 15,
      "participants": []
   },
   "Drama Club": {
      "description": "Theater arts and performance training",
      "schedule": "Tuesdays, 4:00 PM - 6:00 PM",
      "max_participants": 25,
      "participants": []
   },
   "Debate Team": {
      "description": "Learn public speaking and argumentation skills",
      "schedule": "Thursdays, 3:30 PM - 5:00 PM",
      "max_participants": 16,
      "participants": []
   },
   "Science Club": {
      "description": "Hands-on experiments and scientific exploration",
      "schedule": "Fridays, 3:30 PM - 5:00 PM",
      "max_participants": 20,
      "participants": []
   }
}

⌨️ Activity: Use Copilot to describe our work 💬

Nice work fixing that bug and expanding the example activities! Now let's get our work committed and pushed to GitHub, again with the help of Copilot!

  1. In the left sidebar, select the Source Control tab.

    Tip: Opening a file from the source control area will show the differences to the original rather than simply opening it.

  2. Find the app.py file and press the + sign to collect your changes together in the staging area.

    image

  3. Above the list of staged changes, find the Message text box, but don't enter anything for now.

    • Typically, you would write a short description of the changes here, but now we have Copilot to help out!
  4. To the right of the Message text box, find and click the Generate Commit Message with Copilot button (sparkles icon).

  5. Press the Commit button and Sync Changes button to push your changes to GitHub.

  6. Wait a moment for Mona to check your work, provide feedback, and share the next lesson.

Having trouble? 🤷

If you don't get feedback, here are some things to check:

  • Make sure your pushed the src/app.py file changes to the branch accelerate-with-copilot.

Copy link
Contributor Author

github-actions bot commented Mar 24, 2025

🎉🎉🎉 Nice work! Everything is perfect! 🎉🎉🎉
Preparing content for step 3! One moment... 🤓

Copy link
Contributor Author

Step 3: Getting work done even faster with Copilot Edits

In our previous steps, we used features of Copilot that require more hands-on guidance and they produced mostly localized results. Now, we will explore Copilot Edits, a feature that allows working more holistically on our repo.

Copilot Edits is an AI-powered code editing session to make changes across multiple files using natural language, and applies the edits directly in the editor, where you can review them in-place, with the full context of the surrounding code.

Key features

  • Multi-file Editing: Copilot Edits can make changes across multiple files in your workspace.
  • Iterative Workflow: Designed for fast iteration, allowing you to review, accept, or discard AI-generated code.
  • In-place Edits: Shows generated code directly in your editor, providing a code review-like flow.
  • Working Set: Allows you to define which files the edits should be applied to.

How it works

  1. Set Context: Select files to be in the working set.
  2. Provide Instructions: Use natural language to describe the required changes.
  3. Review Changes: See proposed changes in-place in your code.
  4. Accept or Discard: Review each suggested edit and choose which to keep.
  5. Iterate: If needed, provide follow-up instructions to refine the changes.

⌨️ Activity: Use Copilot to add a new feature! 🚀

  1. If the Copilot Chat panel is not visible, please reopen it.

  2. In the top left part of Copilot Chat window, click the Copilot Edits icon to switch modes.

    image
  3. Open the files related to our webpage then drag each editor window (or file) to the chat panel, informing Copilot to use them as context.

    • src/static/app.js
    • src/static/index.html
    • src/static/styles.css

    Tip: You can also use the Attach files... button to provide other sources of context items, like a GitHub issue, the entire codebase, or the results of a terminal window.

  4. Ask Copilot to update our project to display the current participants of activities. Wait a moment for the edit suggestions to arrive and be applied.

    Prompt

    Hey Copilot, can you please edit the area where activities are
    listed on the website to show what participants are already signed up for that activity.
    
    • An extra icon has appeared next to the file names and open editor windows indicating they have suggested edits.

    • A suggested edits panel has appeared in the bottom right of the editor window providing controls to jump to the recommended changes.

      files with icons indicating they have been edited edit navigation panel
    Need help? 🤷

    Remember, to add the relevant files to the working set.

    image

  5. Before we simply accept the changes, please check our website again and verify everything is updated as expected. Here is an example of an updated activity card. You may need to restart the app or refresh the page.

    Activity card with participant info

    Note: Your activity card may look different. Copilot won't always produce the same results.

    Need help? 🤷
    If the website is not loading, here are some things to check.
    • Restart the VS Code Debugger to make sure the latest version of the website is served.
    • If you forgot the url, or closed the window, please review step 1.
    • Try hard refreshing the webpage or opening in a private window so it downloads a fresh copy.
  6. Now that we have confirmed our changes are good, use the panel to cycle through each suggested edit and press Keep to apply the change.

    Tip: You can accept the changes directly, modify them, or provide additional instruction to refine them using the chat interface.

  7. With our new feature complete, please commit and push the changes to GitHub.

  8. Wait a moment for Mona to check your work, provide feedback, and share the the final lesson. Almost done!

Having trouble? 🤷

If you don't get feedback, here are some things to check:

  • Make sure your commite the changes in the src/static/ directory to the branch accelerate-with-copilot and pushed/synchronized to GitHub.
  • If Mona found a mistake, simply make a correction and push your changes again. Mona will check your work as many times as needed.

Copy link
Contributor Author

github-actions bot commented Mar 24, 2025

Step 3 - Fail ❌

Some checks failed. Please review the results below and try again.

Time to find the bug! 🤔

Status Name Message
✅ - Pass app.js
❌ - Fail styles.css Please use Copilot to update the web application styling to support participant info.

Tips

  • Copilot is becoming more capable everyday. Make sure to always be experimenting!
  • Try testing what Copilot can do. Something like: Add a dark mode toggle in the top right.

@david-juran
Copy link
Owner

david-juran commented Mar 24, 2025

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant