Git 路線圖Git Roadmap單元 02Unit 02
準備環境Environment setup

安裝與初始設定Install and configure Git

UNIT 02 · INSTALL & CONFIG

安裝與初始設定Install and configure Git

在 Windows 或 macOS 安裝 Git,並設定每個 commit 都會記錄的作者資訊。Install Git on Windows or macOS and set the author information recorded in every commit.

預計時間Estimated time
15–20 分鐘15–20 minutes
單元類型Unit format
圖解教材Visual lesson
需要先會Prerequisite
可安裝軟體的權限Permission to install software

先確認工具,再開始記指令

Git 是安裝在電腦上的版本管理工具;GitHub 是網路上的協作平台,兩者不是同一套軟體。安裝完成後,先在 Terminal 輸入 git --version,看到版本號才代表 Git 可以使用。

每個 commit 都會記錄作者。請把下列資料換成你自己的公開名稱與信箱:

git config --global user.name "你的名字"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

--global 代表這台電腦上的所有 repository 共用。公司專案若需要另一組資料,可在該 repository 內移除 --global 重新設定。

跨平台最容易踩到的地方

Windows 常用 PowerShell,macOS 預設使用 Terminal 與 zsh;本課程的 Git 指令兩邊相同。路徑與 shell 指令可能不同,因此請不要把 PowerShell 的環境設定直接貼到 zsh。

Windows 常見 CRLF,macOS/Linux 常見 LF。Git 可以協助轉換,但團隊仍應用 .gitattributes 明確約定,不要只靠每個人的電腦預設值。

Check the tools before memorising commands

Git is a version-control tool installed on your computer. GitHub is an online collaboration platform; they are not the same software. After installation, run git --version in a Terminal. A version number confirms that Git is available.

Every commit records an author. Replace the values below with your public name and email:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

--global shares these settings across every repository on this computer. For a project that needs another identity, remove --global inside that repository.

The easiest cross-platform trap

Windows commonly uses PowerShell; macOS uses Terminal and zsh by default. Git commands in this course are the same on both, but paths and shell commands can differ, so do not paste PowerShell environment settings into zsh.

Windows often uses CRLF, while macOS and Linux often use LF. Git can help convert line endings, but a team should still define the rule explicitly with .gitattributes instead of relying on each computer's defaults.

PLATFORM GUIDE

選擇你的電腦Choose your computer

兩邊完成後使用的 Git 指令相同,差別主要在安裝工具與憑證保存位置。The Git commands are the same on both platforms; the main differences are installation tools and credential storage.

WINDOWS 10 / 11

Git for Windows+PowerShellGit for Windows + PowerShell

  1. 從 Git 官方安裝程式安裝,預設選項即可開始。Install from the official Git installer; the default options are fine.
  2. 開啟 PowerShell,而不是把指令貼進瀏覽器。Open PowerShell instead of pasting commands into a browser.
  3. 輸入 Run git --version,確認看到版本號。 and confirm that a version appears.
  4. HTTPS 認證通常交由 Windows Credential Manager 保存。HTTPS credentials are usually stored by Windows Credential Manager.
PowerShellgit config --global core.autocrlf true

macOS

Terminal+zshTerminal + zsh

  1. 在 Terminal 輸入 Run git --version in Terminal.
  2. 若系統提示,安裝 Apple Command Line Tools。Install Apple Command Line Tools if macOS prompts you.
  3. 重新開啟 Terminal,再確認版本號。Reopen Terminal and check the version again.
  4. HTTPS 認證通常由 macOS Keychain 保存。HTTPS credentials are usually stored by macOS Keychain.
Terminal · zshgit config --global core.autocrlf input

CHECKPOINT

離開前,確認你能用自己的話說明Before you leave, explain it in your own words

  1. 這些指令改變 Git 的哪一個區域?
  2. Git 樹上的 branch 與 HEAD 移到哪裡?
  3. 失敗時 repository 是否保持原狀?
  4. 真實專案操作前,應先查看什麼?
  1. Which Git area does this command change?
  2. Where do the branch and HEAD move in the Git tree?
  3. Does the repository stay unchanged when the command fails?
  4. What should you check before operating on a real project?

免責聲明:本站內容為個人學習、實作與經驗分享紀錄,部分內容透過 AI 協助修正與整理。由於每位使用者的系統環境、軟體版本、權限設定與操作方式不同,實際結果可能有所差異。請在操作前自行評估風險並備份重要資料。因參考本站內容所造成之任何系統異常、資料遺失、設定錯誤、設備故障、服務中斷或其他直接、間接損失,均由使用者自行承擔,本站與作者不負任何相關責任。

Disclaimer: This site records personal learning, implementation, and experience sharing, with some content edited and organised with AI assistance. Results may differ because every user has a different system environment, software version, permission setup, and workflow. Assess risks and back up important data before trying anything. You are responsible for any system errors, data loss, configuration mistakes, equipment faults, service interruptions, or other direct or indirect losses resulting from using this content.