在 VS Code 中設定 GitHub Copilot

本指南將引導您在 Visual Studio Code 中設定 GitHub Copilot。若要在 VS Code 中使用 Copilot,您必須透過您的 GitHub 帳號擁有 GitHub Copilot 的存取權。

請按照下列步驟開始在 VS Code 中使用 Copilot

  1. 將滑鼠懸停在狀態列的 Copilot 圖示上,並選擇使用 AI 功能 (Use AI Features)

  2. 選擇登入方式並依照提示操作。

    重要

    自 2026 年 4 月 20 日起,Copilot Pro、Copilot Pro+、Max 及學生方案的新註冊將暫時暫停。

  3. 開始在 VS Code 中使用 Copilot!

    透過 Copilot 快速入門學習基礎知識。

  4. 在聊天對話中輸入 /init 以為您的專案設定 AI。

    /init 指令會分析您的程式碼庫並建立自訂指令 (custom instructions),協助 AI 產生符合您編碼習慣的程式碼。

重要

目前 GitHub Copilot 免費版已啟用遙測功能。根據預設,系統允許符合公開程式碼的程式碼建議(包含 VS Code 和 github.com 體驗中的程式碼參考)。您可以透過將 VS Code 中的 telemetry.telemetryLevel 在 VS Code 中開啟 在 VS Code Insiders 中開啟 此設定由組織層級管理。請聯絡您的管理員進行變更。 設定為 off 來選擇退出遙測資料收集,或者您也可以在 Copilot 設定中調整遙測與程式碼建議設定。

使用 GHE 帳號使用 Copilot

如果您的 Copilot 訂閱與 GitHub Enterprise (GHE) 帳號關聯,您可以使用您的 GHE 憑證登入 VS Code 中的 Copilot。

  1. 如果尚未操作,請將滑鼠懸停在狀態列的 Copilot 圖示上,並選擇使用 AI 功能 (Use AI Features)

  2. 在登入對話框中,選擇以 GHE.com 繼續 (Continue with GHE.com) 並提供您的 GHE 執行個體網址與憑證。

如果您需要在 GitHub.com 帳號與 GHE 帳號之間切換,請參閱針對每個工作區或設定檔使用不同的 GitHub 帳號以取得說明。

使用不同的 GitHub 帳號使用 Copilot

如果您的 Copilot 訂閱與另一個 GitHub 帳號關聯,請按照下列步驟登出您在 VS Code 中的 GitHub 帳號,並以另一個帳號登入。

  1. 選擇活動列中的帳號 (Accounts) 選單,然後選擇您目前登入帳號的登出 (Sign out)

    Accounts menu in VS Code, showing the option to sign out of the current GitHub account.

  2. 使用以下任一方式登入您的 GitHub 帳號

    • 從狀態列的 Copilot 選單中選擇登入以使用 Copilot (Sign in to use Copilot)

      Sign in to use Copilot from the Copilot status menu.

    • 選擇活動列中的帳號 (Accounts) 選單,然後選擇登入 GitHub 以使用 GitHub Copilot (Sign in with GitHub to use GitHub Copilot)

      Accounts menu in VS Code, showing the option to sign in with GitHub to use GitHub Copilot.

    • 在命令面板中執行 GitHub Copilot: 登入 (GitHub Copilot: Sign in) 指令 (⇧⌘P (Windows, Linux Ctrl+Shift+P))。

針對每個工作區或設定檔使用不同的 GitHub 帳號

您可以針對每個 VS Code 工作區或設定檔使用不同的 GitHub 帳號來使用 Copilot。如果您在工作與個人專案中使用不同的 Copilot 帳號,或是希望針對使用 GitHub 驗證的不同擴充功能使用不同帳號,這會非常實用。

請按照下列步驟設定要為 Copilot 使用的 GitHub 帳號。此設定會針對每個工作區及每個設定檔進行儲存。

  • 針對 GitHub.com 帳號

    1. 在活動列的「帳號」選單中,選擇管理擴充功能帳號偏好設定 (Manage Extension Account Preferences)
    2. 從擴充功能清單中選擇 GitHub Copilot Chat
    3. 選擇您要在目前工作區與設定檔中為 Copilot 使用的 GitHub 帳號
  • 針對 GHE.com 帳號

    提示

    如果您只想為 Copilot 使用 GHE 帳號,請依照使用 GHE 帳號使用 Copilot 中的步驟,使用您的 GHE 帳號登入。

    1. 從命令面板執行 偏好設定:開啟使用者設定 (JSON) (Preferences: Open User Settings (JSON))偏好設定:開啟工作區設定 (JSON) (Preferences: Open Workspace Settings (JSON)) (⇧⌘P (Windows, Linux Ctrl+Shift+P))

    2. 新增以下設定,將 GitHub Enterprise 指定為 Copilot 的驗證提供者

      "github.copilot.advanced": {
          "authProvider": "github-enterprise"
      }
      
    3. 如果您尚未登入,請重新登入您的 GitHub Enterprise 帳號

從 VS Code 中移除 AI 功能

您可以透過 chat.disableAIFeatures 在 VS Code 中開啟 在 VS Code Insiders 中開啟 設定來停用 VS Code 內建的 AI 功能,這與您設定 VS Code 中其他功能的方式類似。這將停用並隱藏 VS Code 中的聊天或內嵌建議等功能,並停用 Copilot 擴充功能。您可以針對工作區或使用者層級進行此設定。

或者,使用標題列聊天功能表中的 Learn How to Hide AI Features 動作來存取該設定。

注意

如果您先前已停用內建的 AI 功能,則在更新到新版本的 VS Code 時,您的選擇將會被保留。

為工作區停用 AI 功能

若要為特定工作區停用 AI 功能,請在工作區設定中設定 chat.disableAIFeatures 在 VS Code 中開啟 在 VS Code Insiders 中開啟 設定。此設定可在設定編輯器 (⌘, (Windows, Linux Ctrl+,)) 中找到,或者您也可以編輯工作區中的 settings.json 檔案。

後續步驟

© . This site is unofficial and not affiliated with Microsoft.