If you’re like most developers, you probably use GitHub every day. If you’re not using GitHub, you should be! It’s an essential tool for managing code repositories and collaborating with other developers on projects.
But even if you’re a seasoned GitHub user, there’s always more to learn. That’s where GitHub Copilot comes in. Copilot is a new service that pairs you with a professional developer who can help you with your projects and answer any questions you might have.
Whether you’re just getting started with GitHub or you’re looking to take your skills to the next level, Copilot can help you achieve your goals.
Table of Content
Things You Should Know To Use GitHub Copilot
- You have Visual Code Studio installed on your computer.
- You can clone your existing repository or clone another person’s existing repository to collaborate on a project.
- You need to follow the steps carefully to be able to clone the GitHub repository.
How Does It Work?
GitHub Copilot is really easy to use. Just sign up for an account and then select the project you need help with. After that, you’ll be matched with a developer who has experience with the specific language or framework you’re working with. From there, you can chat with your copilot through the app or over email to get help with whatever issue you’re facing.
For example, let’s say you’re working on a Django project and you need help setting up a development environment. Your copilot can walk you through the process of installing Django and creating a virtual environment so that you can get started coding right away. Or maybe you’re having trouble understanding how to use Git for collaborative projects. Your copilot can explain the basics of Git and how to use it for team-based development.
How to Set Up Copilot on GitHub
Step 1: Install Visual Code Extension
You must first install the Visual Studio Code extension before you can use GitHub Copilot.
- Navigate to the GitHub Copilot extension page in the Visual Studio Code Marketplace and click Install.
- A popup window will appear, prompting you to launch Visual Studio Code. Open Visual Studio Code by clicking the Open button.
- Click Install in the “Extension: GitHub Copilot” tab of Visual Studio Code.
- You will be prompted to sign in to GitHub in Visual Studio Code if you have not previously authorized Visual Studio Code in your GitHub account.
– If you have previously authorized Visual Studio Code for your GitHub account, GitHub Copilot will be authorized automatically.
- GitHub will request the necessary permissions for GitHub Copilot in your browser. Click Authorize Visual Studio Code to approve these permissions.
- To confirm the authentication in Visual Studio Code, click Open in the “Visual Studio Code” dialog box.
Step 2: Seeing your first suggestion
Note: If you have duplication detection enabled for GitHub Copilot, you may receive limited suggestions, or no suggestions, when using the code examples provided. As an alternative, you can start by typing your own code to see suggestions from GitHub Copilot. For more information on duplication detection, see “Enabling or disabling duplication detection.”
GitHub Copilot offers suggestions for a wide range of languages and frameworks, but it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. The following examples are in JavaScript, but they will work in other languages as well.
- Create a new JavaScript (*.js) file in Visual Studio Code.
- Type the following function header into the JavaScript file. As shown below, GitHub Copilot will automatically suggest an entire function body in gray text. The precise suggestion may differ.
- To accept the suggestion, press Tab.
Step 3: Seeing alternative suggestions
GitHub Copilot may provide multiple suggestions for any given input. You can choose which suggestion to use or reject.
1. Create a new JavaScript (*.js) file in Visual Studio Code.
2. Type the following function header into the JavaScript file. GitHub Copilot will make a recommendation.
function calculateDaysBetweenDates(begin, end) { |
3. You can also view alternative suggestions if any are available.
OS | See next suggestion | See previous suggestion |
macOS | Option (⌥) or Alt+] | Option (⌥) or Alt+[ |
Windows | Alt+] | Alt+[ |
Linux | Alt+] | Alt+[ |
4. You can also hover over the suggestion to see the GitHub Copilot command palette for selecting suggestions.
5. Press the Tab to accept a suggestion. Press Esc to reject all suggestions.
Step 4: Seeing multiple suggestions in a new tab
You might not want any of the first suggestions made by GitHub Copilot. You can ask GitHub Copilot to show you multiple suggestions in a new tab by using a keyboard shortcut.
1. Create a new JavaScript (*.js) file in Visual Studio Code.
2. Type the following function header into the JavaScript file. GitHub Copilot will make a recommendation.
function calculateDaysBetweenDates(begin, end) { |
3. Ctrl+Enter will open a new tab with several additional options.
4. To accept a suggestion, click Accept Solution above the suggestion. Close the tab to reject all suggestions.
Step 4: Generating code suggestions from comments
Within a comment, you can describe something you want to do in natural language, and GitHub Copilot will suggest code to accomplish your goal.
1. Create a new JavaScript (*.js) file in Visual Studio Code.
2. Enter the following comment in the JavaScript file. GitHub Copilot will suggest an implementation of the function.
// find all images without alternate text
// and give them a red border function process() { |
Step 5: Using a framework
You can also use GitHub Copilot to generate API and framework suggestions. The example below employs GitHub Copilot to build a simple Express server that returns the current time.
1. Create a new JavaScript (*.js) file in Visual Studio Code.
2. Enter the following comment into the JavaScript file and press Enter. GitHub Copilot will recommend an Express app implementation.
// Express server on port 3000 |
3. To accept each line, press Tab followed by Enter.
4. Enter the following comment after typing it. GitHub Copilot will suggest a default handler implementation.
// Return the current time |
5. To accept each line, press Tab.
Step 6: Enabling or disabling GitHub Copilot
From within Visual Studio Code, you can enable or disable GitHub Copilot. The GitHub Copilot status icon in the Visual Studio Code window’s bottom panel indicates whether GitHub Copilot is enabled or disabled. When enabled, the icon’s background color will match the color of the status bar. When disabled, the icon’s background color contrasts with the color of the status bar.
- Click the status icon in the bottom panel of the Visual Studio Code window to enable or disable GitHub Copilot.
- When you disable GitHub Copilot, you’ll be asked if you want to disable suggestions globally or just for the language of the file you’re currently editing.
– Click Disable Globally to disable GitHub Copilot suggestions globally.
– Click Disable for LANGUAGE to disable GitHub Copilot suggestions for the specified language.
Tips
If you want to be a successful developer, it’s important to have a strong understanding of GitHub. But even if you’re already using GitHub on a daily basis, there’s always more to learn. That’s where GitHub Copilot comes in.
Copilot is a new service that pairs you with an experienced developer who can help answer any questions you might have about using GitHub—no matter what your experience level is. So if you’re looking to take your development skills to the next level, sign up for GitHub Copilot today!