Using GitHub Copilot in Daily Development

Jul 15, 2024

Using GitHub Copilot in Daily Development

Introduction

  • Scenario: New job/project, unfamiliar codebase, no developers to ask.
  • Solution: Use GitHub Copilot as an AI pair programmer.

Initial Steps with GitHub Copilot

  1. Open Repository: Example - pet-spotter repo (an app to locate lost pets using photos).
  2. Using Copilot via GitHub: Click the Copilot icon beside the username.
  3. Generic Questions: Can ask questions like "How do I shorten a URL" before indexing repository.
  4. Index Repository: Click on Copilot and choose to index the repository. This takes a few minutes.

Interacting with GitHub Copilot

  • Immersive View: View numerous topics and popular repositories.
  • Repository Specific Questions: After indexing, ask specific queries, like "How does the pet-spotter app work?"

Local Setup

  1. Clone Repository: Use terminal commands to clone the repository (GH repo clone <repo_owner/repo_name>).
  2. Open in Editor: Load repo in Visual Studio Code (VS Code).
  3. Verify Copilot in VS Code: Ensure GitHub Copilot and GitHub Copilot Chat extensions are installed.

Exploring & Modifying Code

  • Explain Code: Use Copilot to explain code components (e.g., a form for reporting lost pets).
  • Modify Form: Update the form to include new functionalities like location input.
  • Add Drop-down Selector: Change input field to drop-down for location with options.
  • Update Model Class: Add new properties (e.g., location) to data models.

Commit & Pull Requests

  1. Commit Changes: Use GitHub Desktop to commit and create a new branch (mish-manners-changes).
  2. Create Pull Request (PR): Use Copilot to generate a descriptive summary for the PR.
  3. Review Process: Ensure the PR contains detailed information for reviewers.

Best Practices

  • Testing: Always test code before committing changes.
  • Responsibility: Developers are responsible for reviewing Copilot's suggestions and final code output.
  • Detailed Descriptions: Commit messages and PR summaries should be detailed and descriptive.

Conclusion

  • Empowerment: GitHub Copilot helps unblock developers and enhances productivity.
  • Responsibility: Developers remain responsible for the final code.
  • Tips: Always review Copilot's work and collaborate with senior developers when needed.

Happy Coding!