閱讀英文

練習 - 設定軟體以與 GitHub 互動

已完成

既然您已建立 GitHub 帳戶和 learn-git 存放庫,接下來就可以安裝軟體,讓您與 GitHub 存放庫互動更簡單。 您必須先安裝 Visual Studio Code,接著安裝 Git,然後設定 Visual Studio Code。

安裝 Visual Studio Code

  1. 移至 https://code.visualstudio.com/Download
  2. 下載您的作業系統適用的 Visual Studio Code。
  3. 使用預設選項安裝 Visual Studio Code。

重要

開始 Git 安裝之前,您必須先完成 Visual Studio Code安裝,否則無法選取 Git 中的某些選項。

現在已安裝 Visual Studio Code,其將會在 Git 安裝期間做為選取項目使用。 安裝 Git 繼續執行。

安裝 Git

  1. 請前往 https://git-scm.com/downloads

  2. 下載您的作業系統適用的 Git。

  3. 使用下列自訂選取項目來安裝 Git - 所有其他選取項目均可保留為預設值。

  4. 選擇 Git 所使用的預設編輯器 - 設定為 [使用 Visual Studio Code 作為 Git 的預設編輯器]。

    Screenshot of the default editor selection during Git install.

  5. 調整新存放庫中初始分支的名稱 - 設定為 [覆寫新存放庫的預設分支名稱],然後在文字方塊中輸入 main

    Screenshot of the initial branch default being set to main during Git install.

注意

只有步驟 4 和 5 需要自訂設定。 其餘的 Git 安裝都可以使用預設值來完成。

設定 Visual Studio Code

對此專案的大部分,您將使用 Visual Studio Code 的終端機視窗,從 Git 命令列執行命令。 熟悉命令列可以大幅改善您的 Git 體驗。 您不必瀏覽不同的功能表並回想找到不同設定的位置,而是可以從終端機視窗執行所有動作。

開啟終端機視窗。

  1. 啟動 Visual Studio Code
  2. 在功能表列上,選取 [終端機]>[新增終端機],或使用快速鍵組合 [CTRL '] (控制倒單引號),以在 Visual Studio Code 中開啟終端機。
  3. 將終端機類型變更為 Git Bash

注意

根據預設,Visual Studio Code 一律會在 PowerShell 模式中開啟終端機視窗。 您可以在變更為 Git Bash 的相同功能表上,使用 [選取預設設定檔] 選項來變更該預設值。

設定 Git 設定和目錄

現在我們將使用 batch 命令和 Git 命令的組合來建立 Git 存放庫資料夾,並設定我們的全域使用者名稱和電子郵件。 在終端機視窗中,執行下列命令。

命令 動作
cd c:/ 從任何位置變更為 C 磁碟機的根目錄。
mkdir git-repos 在 C 磁碟機上建立新的目錄 git-repos
cd git-repos 新建立 git-repos 目錄的變更。
git config --global user.name "Victoria Burke" 針對所有 git 存放庫設定您的使用者名稱,以協助識別認可。*以您的 GitHub 使用者名稱取代 Victoria-Burke。
git config --global user.email "vburke@contoso.com" 針對所有 git 存放庫設定您的電子郵件地址,以協助識別認可。*以與您的 GitHub 帳戶相關聯的電子郵件取代 vburke@contoso.com。

Screenshot of VS Code with the configuration commands run.

恭喜! 您已成功安裝 Git 和 Visual Studio Code。 您也已將 Visual Studio Code 設定為開始使用 Git 存放庫。