# GitHub 基本操作 — Day 2
> 主題:Git 安裝 & 本地端操作(clone、commit、push)
---
## 課程目標
1. 安裝 Git 並完成基本設定
2. 從 GitHub clone 一個專案到本地端
3. 在本地修改檔案並進行 commit
4. 將修改 push 回 GitHub
---
## 第一單元:Git 安裝與設定
----
### Windows / macOS 安裝
* [Git 官網下載](https://git-scm.com/downloads)
* Windows:執行安裝程式(一路 Next)
* macOS:可用 Homebrew → `brew install git`
----
### Linux 安裝
```bash
sudo apt-get install git # Ubuntu / Debian
sudo yum install git # CentOS / Fedora
```
----
### 基本設定(首次安裝必做)
```bash
git config --global user.name "你的名字"
git config --global user.email "你的Email"
```
確認是否設定成功:
```bash
git config --list
```
---
## 第二單元:Clone 專案到本地端
----
### 為什麼要 clone?
* 把 GitHub 上的專案「複製」到自己電腦
* 可以在本地修改,並透過版本控制保存紀錄
----
### 實際操作
1. 打開一個 Repo(例如昨天的 `hello-github`)
2. 點擊綠色 **Code** 按鈕 → 複製 HTTPS 連結
3. 在電腦上開啟終端機 (Terminal / Git Bash)
4. 移動到你要放專案的資料夾
5. 輸入:
```bash
git clone https://github.com/USERNAME/hello-github.git
```
6. 進入資料夾:
```bash
cd hello-github
```
---
## 第三單元:修改檔案並 Commit
----
### 修改檔案
* 用文字編輯器修改 `hello.txt`(例如新增一行 `This is my local edit.`)
----
### 檢查修改狀態
```bash
git status
```
----
### 將檔案加入暫存區(staging area)
```bash
git add hello.txt
```
----
### 建立 commit
```bash
git commit -m "Update hello.txt: add local edit"
```
---
## 第四單元:Push 回 GitHub
----
### 上傳修改到遠端 Repo
```bash
git push origin main
```
> 注意:若預設 branch 是 `master`,需改為 `master`
----
### 確認結果
* 回到 GitHub 網頁 → 檢查檔案是否已更新
---
## 實作練習
### 練習目標
1. 從自己的 GitHub clone `hello-github` 專案到電腦
2. 修改 `hello.txt` 並新增一行文字
3. 使用 `git add`、`git commit`、`git push` 將修改推送回 GitHub
----
### 檢查清單
* [ ] 成功 clone Repo
* [ ] 成功 commit 修改
* [ ] 成功 push 並在 GitHub 上看到更新
---
## 常見問題(Instructor Tips)
1. **git push 出錯(拒絕權限)**:檢查是否登入 GitHub 帳號,或是否使用正確的 HTTPS/SSH URL。
2. **無法 commit**:確認是否先 `git add`。
3. **branch 不符**:部分 Repo 預設是 `main`,部分是 `master`,需確認名稱。
---
## 課程回顧
* Git 安裝與設定
* Clone Repo 到本地
* 本地修改 → add → commit
* Push 修改到 GitHub
---
## 下一堂課預告
* GitHub 分支(branch)與協作流程
* Pull Request 的基礎操作
---
## 範例指令快速複製
```bash
git clone https://github.com/USERNAME/hello-github.git
cd hello-github
echo "This is my local edit." >> hello.txt
git add hello.txt
git commit -m "Update hello.txt: add local edit"
git push origin main
```
{"title":"GitHub 基本操作 — Day 2","description":"主題:Git 安裝 & 本地端操作(clone、commit、push)時長:約 1 小時","contributors":"[{\"id\":\"b831f9fa-52bb-4a09-bfbb-148e4fdadd0f\",\"add\":2230,\"del\":0,\"latestUpdatedAt\":1759543126667}]"}