Git 路線圖Git Roadmap單元 05Unit 05
遠端同步Remote sync

連接 GitHubConnect to GitHub

UNIT 05 · GITHUB REMOTE

連接 GitHubConnect to GitHub

分清本機 branch、remote-tracking branch 與 GitHub 上的 branch。Separate your local branch, remote-tracking branch, and the branch on GitHub.

預計時間Estimated time
25–30 分鐘25–30 minutes
單元類型Unit format
教材+模擬器Lesson + simulator
需要先會Prerequisite
理解本機 commitUnderstand local commits

push 不是備份目前檔案,而是傳送 commit

origin 只是 remote 的慣用名稱。新增 remote 不會立刻上傳任何東西,第一次 push -u 才會傳送 commit 並建立追蹤關係。

git remote add origin https://github.com/demo/git-lab.git
git remote -v
git push -u origin main
git push
git pull

origin/main 是本機記得的遠端 branch 位置,不等於即時讀取 GitHub。git fetchgit pull 後,它才會更新。

git clone 則是一個組合動作:下載遠端歷史、建立本機 repository、設定 origin,並取出預設 branch 的檔案。

Windows Credential Manager 與 macOS Keychain 會協助保存認證。不要把 Personal Access Token 寫進 remote URL、程式碼或 commit。

push sends commits; it does not back up your current files

origin is simply the conventional name for a remote. Adding a remote uploads nothing. The first push -u sends commits and creates the tracking relationship.

git remote add origin https://github.com/demo/git-lab.git
git remote -v
git push -u origin main
git push
git pull

origin/main is the remote branch position remembered locally; it is not a live read of GitHub. It updates after git fetch or git pull.

git clone combines several actions: download remote history, create a local repository, set origin, and check out the default branch files.

Windows Credential Manager and macOS Keychain can store credentials. Never put a Personal Access Token in a remote URL, source code, or commit.

INTERACTIVE LAB

在安全模擬器裡親手操作

輸入指令後,Terminal、四個區域與 Git 樹會從同一份虛擬狀態同步更新。

A

WORKING DIRECTORY

正在編輯的檔案

  • README.md已提交
  • app.js已提交
  • nav.js已提交
B

STAGING AREA

下一版準備內容

  • Staging Area 是空的
C

LOCAL REPOSITORY

電腦裡的版本

HEAD
→ main
目前 commit
c2
commit 數
2
D

REMOTE REPOSITORY

GitHub 示意狀態

origin
尚未設定
遠端 branch
沒有 commit
網路連線
僅記憶體模擬

教學 Terminal

不會執行真實 Git 或 shell

教學模擬器已就緒。這裡不會執行真實 Git 或讀寫你的檔案。

點一下填入:

VIRTUAL FILES

虛擬檔案編輯器

更多情境工具

LIVE GIT TREE

commit 與 branch

HEAD → main
  1. c2
    HEAD → main
    加入導覽列parent:c1
  2. c1
    建立專案parent:無(第一個 commit)

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.