Code Monkey home page Code Monkey logo

learn-github-copilot's Introduction

Can GitHub Copilot be my AI pair programmer?

What is it

I have heard a lot of noise recently about GitHub Copilot being your AI pair programmer. Being a programmer who loves pairing, I was curious to test this out to see if the fuss was correct.

Following this course on Udemy, I managed to use GitHub Copilot to create a simple web app that allows users to input income and expenses for each month, plot it to a bar chart, then download that chart as an image. It took me around 3 hours in total to create this web app.

This repository has all the code and prompts that I used to create the web app.

How to view the web app

  1. Clone this repository
  2. Open the index.html in a browser

How to setup GitHub Copilot in VS Code

  1. Install VS Code. This is an IDE (integrated development environment) which allows you to write code.
  2. After installing VS Code, open Extensions tab and add GitHub Copilot. This extension provides autocomplete-style suggestions as you code.
  3. Also add GitHub Copilot Labs, a companion extension to GitHub Copilot. This extension provides more advanced and experimental features in the sidebar of VS Code e.g. explaining what the code does, translating a code to a certain language like Python etc.

NOTE: You need to either create or login to a GitHub account. You also need to have a subscription to GitHub Copilot in order to use it. In my case, I subscribed to the free trial which, at the time of writing this ReadMe, was for 30 days. Within this period you can cancel any time to avoid charges.

How to use GitHub Copilot in VS Code

GitHub Copilot is an AI powered coding assistant that offers autocomplete-style suggestions as you code. There are two ways to trigger suggestions:

  • By writing a comment (a prompt) describing what you want the code to do, or
  • By starting to write the code you want to use.

GitHub Copilot analyses the context and comments in the file you are editing, as well as related files, and provides suggestions in the form of a single line of code or even a block of code.

Trigger GitHub Copilot suggestions by writing a comment

To trigger a suggestion, just start typing a comment (acting as a prompt) describing what the piece of code does. For example, I wrote the below comment and press Enter at the end of the comment. Pressing Enter signifies to Copilot that you want to get suggestions.

<!-- bootstrap tab, with 2 tabs, first one called Data, second one called Chart -->

Screenshot of typing comment to trigger Copilot suggestions

NOTE: A good prompt is crucial to make Copilot return more accurate results. You should write the prompt describing exactly what the code does rather than describing what you want.

Example of a good prompt (which explains what the code does):

<!-- bootstrap tab, with 2 tabs, first one called Data, second one called Chart -->

Example of a bad prompt (which explains what you want Copilot to do):

<!-- Create a bootstrap tab, with 2 tabs, first one called Data, second one called Chart -->

After pressing Enter, just wait for a moment and you will notice at the status bar of your VS Code, Copilot is processing your prompt.

Screenshot of Copilot processing comment

After Copilot is done processing your comments, it displays the result to your screen. If you're happy with the suggestion, click Tab to accept it. You can look at other suggestions if there is more than one.

Screenshot of Copilot giving suggestions

Trigger GitHub Copilot suggestions by writing the code

Another way of triggering suggestions is quite simple, just start writing the code and Copilot will give suggestions on the fly similar to IntelliSense. To accept a suggestion, similar to how I explained above, press Tab.

Screenshot of triggering Copilot suggestions by writing the code

My closing thoughts on using GitHub Copilot

I have a lot of thoughts and opinions about Copilot. However, I will refrain from listing them here so you do not get spoilers and can try Copilot without any bias. Here is my blog that I wrote about my opinions. Happy reading!

learn-github-copilot's People

Contributors

maiisthebest avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.