Name
    Email
    Subject
    Message

    How to Use GitHub Copilot

    Applied Math Consulting > Ideas  > How to Use GitHub Copilot

    How to Use GitHub Copilot

    GitHub Copilot is one of the most popular AI assistants for writing code. Find out how to communicate your intent to GitHub Copilot properly and write code faster, avoiding unnecessary trials and errors.

    In this blog post, we explain how to make the most out of GitHub Copilot and even how to gain free access.

     

    What is GitHub Copilot?

     

    GitHub Copilot is an AI tool designed to assist developers in writing code. Branded as an AI pair programmer, it uses a vast database of open source code and machine learning algorithms to understand the context of the code and provides suggestions for lines or whole blocks of code as you type.

    What sets GitHub Copilot apart from other similar solutions is its emphasis on user control. You are free to accept or reject its code suggestions, edit them manually, and browse through different options.

    How does GitHub Copilot work?

    GitHub Copilot’s suggestions are based on various contextual cues in your file, like function names, comments, docstrings, and the cursor’s position. This is especially helpful if you are working with unfamiliar frameworks and libraries. Copilot can quickly read through open source documentation and offer you relevant information and code snippets in seconds.

    The tool supports all programming languages and can even work with plain text, creating suggestions based solely on the context within the file. One of the standout features of GitHub Copilot is its ability to understand both programming and natural human languages. However, its recommendations are not always perfect: some might not be practical or not make sense in certain contexts.

    Also, keep in mind that GitHub Copilot doesn’t test the code it suggests. The program might not compile or run correctly, so it’s essential to review and test it thoroughly before use.

    How to get started with GitHub Copilot

    It’s really easy to start using GitHub Copilot, you just need to install the extension and learn a few keyboard shortcuts.

    Install the extension

    GitHub Copilot isn’t included by default in any text editors, so you’ll need to install it as an extension. For that, you can use:

    • Visual Studio Code Marketplace,
    • JetBrains Marketplace,
    • Neovim Plugin for GitHub Copilot.

    Once installed, Copilot will ask you to log in to GitHub to authorize the plugin. After that, you’ll be redirected back to your editor. Check for the Copilot icon in your editor’s status panel to see if the installation has been successful.

    Learn the keyboard shortcuts

    The main keyboard shortcuts for GitHub Copilot vary slightly across macOS, Windows, and Linux platforms. So familiarize yourself with the following essential shortcuts:

    ActionKeys
    Accept inline code suggestionTab
    Dismiss inline code suggestionEsc
    Show next suggestionUse Alt + ] (or Option (⌥) + ] on macOS)
    Show previous suggestionUse Alt + [ (or Option (⌥) + [ on macOS)
    Trigger suggestionUse Alt + \ (or Option (⌥) + \ on macOS)
    Open ten suggestions in a separate paneCtrl + Enter

    Keep this list handy as a quick reference while you work with GitHub Copilot and remember that shortcuts for different IDEs may vary.

    For more beginner tips, watch this video:

     

    Now your AI pair programmer is ready for work. In the following section, we’ll explain how to get the most of it.

    GitHub Copilot best practices

    GitHub Copilot has been trained on a vast array of code examples, enabling it to generate numerous predictions for the next line of code. The rule of thumb is that by providing more context around a specific line, you can help narrow down these predictions.

    The general recommendations would be:

    • Create descriptive names for functions: Meaningful names help Copilot better understand your intentions and provide more accurate suggestions.
    • Guide Copilot with comments: By writing descriptive comments in your code, you can prompt the tool to generate specific code snippets or functions.
    • Explore different scenarios: Experiment with Copilot in various programming scenarios – from writing unit tests to exploring new libraries or frameworks. This approach can provide valuable insights.
    • Provide feedback: Take time to review and refine the suggestions, giving Copilot the right direction aligning with specific project requirements.

    Now, let’s get into the specifics, keeping in mind that your final code serves two audiences: the computer that executes it and the programmers who read it. So, make sure your code is both accurate and comprehensible.

    LLMs like GitHub Copilot are good at identifying and maintaining patterns. That’s why, to enhance Copilot’s effectiveness, it’s recommended to make your code more pattern-based, that is structure it in a way that follows consistent and recognizable patterns or blocks.

    Types

    There are also security concerns. GitHub Copilot requires careful handling when used in conjunction with confidential or NDA-protected code.

    Here’s what you should be aware of:

    • Since the tool was trained on a dataset that includes public code from GitHub, it does not directly access or use private repositories or code that hasn’t been shared publicly. This means it doesn’t “learn” from or “remember” code it sees in private settings or under NDA.
    • If you’re working on code that’s under an NDA, Copilot itself does not “know” that the code is confidential. It will still provide suggestions based on its training.
    • The key concern with using Copilot on NDA-bound code is not that the tool will leak the code (since it doesn’t send your code back to a server or learn from it), but rather ensuring that the suggestions it provides do not inadvertently introduce snippets of code that may be proprietary or sensitive from its training dataset.

    Bottom line: When working with confidential or NDA-protected code, you have to review any code suggestions provided by Copilot. It’s your responsibility as a developer to ensure that the use of such tools complies with their organization’s security policies and the terms of any NDAs.

    For public code, you can use the code referencing feature which presents details about the matching code when you accept its suggestions. However, today it is only available Visual Studio Code.

    Is GitHub Copilot free?

    All good things come at a price. GitHub Copilot for Individuals costs $10 per month or $100 per year for each seat. The Business version is priced at $19 per seat, per month. Fortunately, each subscription comes with a 30-day free trial.

    However, there’s good news. You can use the tool for free if you are a teacher, a student, or a maintainer of popular open-source projects.

    You can find more details on GitHub Copilot’s FAQ page.

    What are GitHub Copilot alternatives?

    There exist several free and paid alternatives to GitHub Copilot. Here are some free options you may want to try:

    Code Whisperer: This tool by Amazon is free for individual use. AWS toolkit extension, which not only provides the coding assistant features of Code Whisperer but also facilitates viewing, modifying, and deploying AWS resources. Code Whisperer supports a variety of programming languages.

    IntelliCode: This is an open-source extension for Visual Studio and Visual Studio Code developed by Microsoft. It generates code suggestions customized to the current context and compatible with numerous languages and frameworks.

    CodeGeex: It is driven by large code repositories of up to 20 programming languages and can convert code between different programming languages.

    TabNine: This AI code assistant offers smart code completion, syntax highlighting, and error checking. It learns from open source datasets and is free for personal use.

    In the video below, you’ll find a comparison of GitHub Copilot with two most popular alternatives: Google’s Duet AI and OpenAI-’s ChatGPT:

     

    Conclusion

     

    GitHub Copilot can significantly streamline your software development progress. To enhance your experience, focus on providing clear context through well-structured, smaller functions and descriptive comments. Experimenting with GitHub Copilot in various coding scenarios helps the tool continuously improve its suggestions related to your code, making it a better helper.

    No Comments

    Sorry, the comment form is closed at this time.