GitHub Copilot Tutorial: From Setup to Agent Mode
Writing code with GitHub Copilot is much more than accepting inline autocompletions. Many developers face browser login freezes on Linux or struggle with hallucinated imports and outdated code suggestions. This guide covers how to install the extension, ground completions with workspace instructions, and navigate agentic terminal workflows.
Before you start
- A GitHub account (Free, Pro, or Enterprise tier)
- Visual Studio Code installed on Linux, macOS, or Windows
- Python 3 and Git installed
Understanding the Copilot Free Tier
GitHub provides a free tier for Copilot that does not require entering payment details. This tier includes two thousand code completions and fifty chat messages every month, making it accessible for personal exploration.
Paid plans such as Copilot Pro and Enterprise offer unlimited completions and expanded model selection. Before setting up your local tools, confirm that Copilot access is enabled inside your GitHub account settings.
VS Code Installation and Linux Authentication
In Visual Studio Code, open the Extensions view and install GitHub.copilot. The modern package includes Copilot Chat directly, so you do not need to install an extra companion extension.
To authenticate, click the Accounts icon in the Activity Bar and select the option to sign in with GitHub. On Linux desktops lacking a desktop keyring service, the browser redirect may freeze. Selecting the device code option generates an eight-character code that you paste into the GitHub login page, bypassing URL callback issues.
Creating Project Workspace and Rules Directory
Copilot relies on workspace context to provide accurate suggestions. You can set up a dedicated project folder and initialize a Git repository to hold both code and Copilot configuration.
Run the tested commands below to build the directory structure and initialize the main branch.
# Initialize project directory and git repository
mkdir -p copilot-demo/.github && cd copilot-demo && git init -b main
Output from our test run
$ mkdir -p copilot-demo/.github && cd copilot-demo && git init -b main
Initialized empty Git repository in /root/copilot-demo/.git/
$Configuring copilot-instructions.md
Inside your configuration directory, create a file named copilot-instructions.md. Copilot automatically parses this file and injects its constraints into both inline suggestions and chat sessions.
Use this file to state your target runtime, framework choices, and formatting guidelines. Clear instructions prevent Copilot from hallucinating uninstalled third-party packages or using deprecated language patterns.
# Project Copilot Instructions
## Technology Stack
- Python 3.12+ with strict type hints
- Standard library unittest for tests
## Coding Standards
- Write pure, deterministic functions wherever possible.
- Do not import third-party libraries without explicit instructions.
- Include docstrings explaining parameters and return values.
- Always write companion unit tests for new logic.
Mastering Ghost Text Autocompletion
As you write code, suggestions appear inline as gray ghost text. You can accept the entire suggestion by pressing Tab, or grab just the next word using your word-advance shortcut.
When alternative implementations are available, cycle through them using the bracket shortcuts Alt + ] and Alt + [. Press Esc to dismiss any suggestion you do not want. Keeping related project files open in editor tabs also improves the quality of ghost text completions.
Context Anchors and Model Switching
Open Copilot Chat directly in your editor to handle refactoring and architectural questions. Rather than submitting generic prompts, attach context anchors like @workspace to query project files or @terminal to debug recent output.
You can also target specific files using #file followed by the path to avoid ambiguous answers. Depending on the task, open the model picker in the chat box to switch between models such as Claude 3.7 Sonnet, GPT-4o, and Gemini 2.5 Pro.
Validating Generated Code with Tests
AI-generated code should always be verified before you commit changes to source control. You can create a small module alongside a test suite to ensure the logic handles both valid inputs and exceptions correctly.
Run the commands below to create calc.py and test_calc.py, then execute the test suite using python3 -m unittest to confirm all assertions pass.
# Create calculator module with add and divide functions
cat << 'EOF' > calc.py
def add(a, b):
return a + b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
EOF
# Create unit test suite covering add and divide operations
cat << 'EOF' > test_calc.py
import unittest
from calc import add, divide
class TestCalc(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
def test_divide(self):
self.assertEqual(divide(10, 2), 5)
with self.assertRaises(ValueError):
divide(5, 0)
EOF
# Run test suite to verify module correctness
python3 -m unittest
Output from our test run
$ cat << 'EOF' > calc.py
> def add(a, b):
> return a + b
> def divide(a, b):
> if b == 0:
> raise ValueError("Cannot divide by zero.")
> return a / b
> EOF
$ cat << 'EOF' > test_calc.py
> import unittest
> from calc import add, divide
> class TestCalc(unittest.TestCase):
> def test_add(self):
> self.assertEqual(add(2, 3), 5)
> def test_divide(self):
> self.assertEqual(divide(10, 2), 5)
> with self.assertRaises(ValueError):
> divide(5, 0)
> EOF
$ python3 -m unittest
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
$Using Copilot in the Terminal
In addition to editor integrations, you can interact with Copilot directly from the command line using the standalone agentic CLI. The tool allows you to explain complex shell pipelines, diagnose errors, and prepare Git commands interactively.
Launch the shell by running copilot, then submit /login to authorize your session. Once authenticated, prompt the interactive shell to review terminal status or generate scripts on the fly.
Wrap-up
You have configured GitHub Copilot with custom project rules, master keyboard shortcuts for ghost text, and verified terminal workflows. Grounding the assistant with specific context anchors and running automated test suites ensures AI assistance remains reliable and productive.
FAQ
Why does signing into GitHub Copilot hang on Linux?
Linux desktop environments that lack a desktop secret service like GNOME Keyring often fail to handle the editor browser redirect. Using the device code flow lets you paste an authentication code into your browser manually.
Do I need to install a separate extension for Copilot Chat?
No, the modern GitHub.copilot extension bundles chat functionality directly, so a detached chat extension is no longer required.
How does copilot-instructions.md help avoid hallucinated code?
The assistant automatically scans the file and applies your specified language versions, constraints, and standard library rules to every inline prompt and chat query.