DEV Community

Aneeqa Khan
Aneeqa Khan

Posted on

How to Integrate GitHub Copilot with VS Code

What is GitHub Copilot

GitHub Copilot, often referred to as “your AI-powered coding assistant,” is an innovative tool designed to enhance the productivity and efficiency of developers. Powered by OpenAI’s Codex, the system behind Copilot is trained on vast amounts of public code and text data, making it a valuable asset for developers by offering contextual code suggestions, improving workflows, and making complex coding tasks easier to manage.


Step 1: Install Visual Studio Code

Before integrating GitHub Copilot, ensure you have VS Code installed on your machine. If you haven’t already installed VS Code, you can download it from the official site:


Step 2: Install the GitHub Copilot Extension

Once VS Code is installed, you need to install the GitHub Copilot extension:

  1. Open Visual Studio Code.
  2. Go to Extensions: Click on the Extensions icon on the left sidebar or press Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (Mac).
  3. Search for GitHub Copilot: In the Extensions Marketplace search bar, type “GitHub Copilot.”
  4. Install the Extension: Once you find the “GitHub Copilot” extension by GitHub, click the Install button.

Alternatively, you can install the extension directly from the Visual Studio Marketplace using this link:


Step 3: Sign in to GitHub

Once the GitHub Copilot extension is installed, you’ll need to sign in to GitHub to activate it:

  1. Open VS Code.
  2. Sign In Prompt: After installing, you’ll likely see a prompt asking you to sign in to GitHub. Click Sign In.
  3. Authorization: A browser window will open, directing you to GitHub. If you’re not already signed in, log in with your GitHub credentials.
  4. Authorize GitHub Copilot: Once logged in, you’ll be prompted to authorize GitHub Copilot to access your account. Click Authorize GitHub Copilot.

After this, GitHub Copilot will be activated and ready to use in VS Code.


Step 4: Configure GitHub Copilot Settings

You can customize GitHub Copilot’s behavior in VS Code by adjusting some settings:

  1. Open Settings: In VS Code, click on the gear icon in the lower-left corner and choose Settings.
  2. Search for GitHub Copilot: In the Settings search bar, type “GitHub Copilot” to see the various options available.
  3. Adjust Settings: You can enable or disable specific Copilot features, like whether Copilot provides inline suggestions, autocompletes, or shows multiple options.

You can also access the Copilot settings by navigating to File > Preferences > Settings and searching for “Copilot.”


Step 5: Start Using GitHub Copilot in VS Code

With GitHub Copilot installed and activated, you’re ready to start coding with its assistance:

  1. Create or Open a File: Open a file or create a new one in a programming language supported by Copilot (e.g., Python, JavaScript, etc.).
  2. Write Code: As you start typing, GitHub Copilot will suggest code snippets, entire functions, or blocks of code based on the context of what you’re writing.
  3. Accept Suggestions: When Copilot makes a suggestion, you can:
  • Press Tab to accept the suggestion.
  • Press Esc to dismiss the suggestion.
  • If multiple suggestions are available, you can view the next suggestion by pressing Alt (Windows/Linux) or Option (Mac) and [ Press Alt or Option and ] to go to the previous suggestion.

Step 6: Review and Use Copilot’s Suggestions

While GitHub Copilot is highly effective, reviewing all suggestions before accepting them is crucial. The AI may not always provide the most optimal solution, so double-check the generated code for accuracy and efficiency.


Optional: Disable GitHub Copilot for Certain Projects

If you want to disable GitHub Copilot for certain projects or files, you can adjust the settings:

  1. Disable in Workspace: You can disable Copilot in a specific project by opening the Command Palette (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on Mac) and searching for "Copilot: Disable for Workspace".
  2. Disable for Specific Languages: You can also disable GitHub Copilot for particular programming languages by adjusting the Copilot settings in the Settings menu.

Conclusion

Integrating GitHub Copilot with Visual Studio Code is simple and can significantly enhance your coding workflow. Once set up, you’ll have access to an AI-powered coding assistant that helps with everything from autocompleting lines of code to generating entire functions based on your input. This tool is especially helpful for increasing productivity, learning new languages, and reducing the time spent on repetitive tasks.

By following the steps outlined above, you can quickly get GitHub Copilot up and running in your VS Code environment and start leveraging the power of AI to write better code faster.


Thank you for reading! Feel free to connect with me on LinkedIn or GitHub.

Top comments (0)