先確認工具,再開始記指令
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
--globalshares these settings across every repository on this computer. For a project that needs another identity, remove--globalinside 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.