Skip to content

本頁由 AI 根據韓語原文翻譯,可能存在錯誤。

第2章 建立 GitHub 倉庫 — 給專案蓋一座房子 ​

必讀 想跟著這個階段學下去,一定要讀這一章。

一句話總結:倉庫(Repository)是存放專案檔案和所有改動記錄的地方。在 GitHub 上建立倉庫,就在我的電腦之外有了一份安全的副本和協作空間。 公開還是私有,關係到以後能不能免費釋出到網上,所以從建立時就要定下來。

這一章依據 2026年11月1日確認的 GitHub 官方文件編寫。GitHub 的介面按英語來寫。如果你在第3階段用 Git 留存過「改動記錄」,可以把這一步想成是把那份記錄放到網際網路上。

Git、GitHub 與倉庫 ​

Git 是追蹤檔案改動的版本管理系統。[1] 在第3階段你對 Claude 說「幫我記錄下來」,那個提交就是 Git 的記錄。

GitHub 是把那個 Git 專案放到網際網路上,並加上計劃和協作工具的服務。[1:1] 而倉庫是把專案的程式碼和檔案放在 GitHub 上的地方。它保管檔案,每次改動都用提交來記錄,併成為一起工作的空間。[2]

常見的詞,請先了解一下。

詞含義
分支(branch)不影響基礎版本、單獨工作的一條支線
合併(merge)把一條支線的改動併入另一條支線
遠端(remote)位於 GitHub 上,而不是我電腦上的倉庫
克隆(clone)把倉庫連同記錄一起下載到我的電腦

出處:GitHub 官方文件(僅摘錄一部分)[3]

理解檢查

關於 Git 和 GitHub 的關係,哪項是對的?

公開與私有 ​

建立倉庫時最先要定的是可見範圍。

範圍誰能看到
公開(Public)網際網路上的任何人
私有(Private)我和我分享給的人

出處:GitHub 官方文件[4]

這本指南選擇 Public(公開)。因為這個選擇與第7章的釋出相關。免費帳號只有在公開倉庫裡才能使用 GitHub Pages(免費的網頁釋出)。[5] GitHub 的入門教程也出於同樣的理由,讓人選擇 Public。[6]

公開倉庫是有代價的。全部程式碼對所有人可見,所以有人盯上弱點或敏感資訊的風險會變大。[7] 因此,公開倉庫裡不要放含有個人資訊·密碼·真實姓名的備忘。 第9章會詳細講。

以後改成私有會怎樣?(點選展開)

以後也可以更改,但會有代價。在免費帳號下把公開倉庫改成私有,已經發布的 Pages 網站會自動下線。[8]

理解檢查

用免費帳號,以後想釋出到 GitHub Pages。倉庫該怎麼建立?

README·.gitignore·許可證 ​

建立新倉庫時,可以同時放進三個檔案。[9]

  • README:訪客最先看到的說明書。[10] 寫明這是一個做什麼的專案、為什麼有用、怎麼開始。教程讓人選擇 Add README。因為它既是起始檔案,又是介紹專案的地方。[11]
  • .gitignore:寫明提交時 Git 要忽略的檔案的清單。[12] 像裝有密碼的設定檔案這類不能上傳的東西,就寫在這裡。要注意一點:已經提交過的檔案,只是寫進清單是不會被忽略的。[13] 所以最好一開始就寫好。
  • 許可證:告訴別人可以用我的程式碼做什麼。不一定非選不可。[14] 如果不選,就適用預設的著作權法,別人不能複製·分發·修改後使用我的程式碼。[14:1] 如果是練習用的倉庫,不選也可以。
如果想選許可證(點選展開)

如果不好選,GitHub 推薦 choosealicense.com 。GitHub 也宣告,這份指引不是法律意見。[15]

上傳已經有 Git 記錄的資料夾時(點選展開)

像這本指南這樣第一次新建倉庫時,不用在意這一點。

匯入已經有 Git 記錄的倉庫時,不要選這三項。GitHub 上新生成的檔案和我資料夾裡的記錄可能會對不上。這時 Git 不知道該保留哪一邊,就會停下來。這叫作合併衝突(merge conflict)。[16]

理解檢查

關於 .gitignore,哪種說法是對的?

與我的電腦連線 ​

把 GitHub 上的倉庫帶到我的電腦上,叫做克隆(clone)。克隆下來的副本和 GitHub 上的原件保持連線,所以我記錄的內容可以再傳上去。[17]

帶過來的方法有好幾種。

方法適合的情況
GitHub Desktop像官方入門教程那樣,用圖形介面
拜託 Claude Code想像第3階段那樣用說的來交代時

出處:本指南的整理(GitHub Desktop 是官方教程的方法)[17:1]

可以這樣拜託 Claude Code。倉庫地址,用在 GitHub 上開啟倉庫時瀏覽器位址列裡顯示的地址(例:https://github.com/你的ID/cafe-todo-board)。

把這個 GitHub 倉庫克隆到 ~/hello-ai-practice/todo-board 資料夾:<倉庫地址>

也可以把已有的資料夾傳上去。 像第3階段的 organizer 那樣,原本就在我電腦裡的資料夾也可以傳到 GitHub 上,如果是一直沒用 Git 管理的資料夾,要先把它做成 Git 倉庫。[18] 不過本指南是把待辦看板建立成新倉庫。 organizer 裡有備忘原件,原樣放到公開倉庫裡,還是避免為好。

理解檢查

把倉庫克隆(clone)到我的電腦上,會怎樣?

親手試一試 ​

  1. 在 github.com 註冊或登入(免費帳號就行)。
  2. 點右上角 + → New repository 建立新倉庫。名稱是 cafe-todo-board,可見範圍選 Public,選擇 Add README。如果能同時放進 .gitignore,就放進去(清單按介面提示選)。
  3. 在倉庫介面確認能看到 README。
  4. 用 GitHub Desktop 或 Claude Code,把倉庫克隆到 ~/hello-ai-practice/todo-board。以後把我電腦裡的記錄傳到 GitHub 上,叫作推送(push)(第4章會講)。要推送,那個工具必須已經登入我的 GitHub 帳號。第一次上傳時如果彈出登入視窗,照著提示做。
  5. 在 Claude Code 應用裡開啟克隆下來的資料夾,確認資料夾裡有 README.md。

連續任務:在第3章裡,我們接受 Claude 的採訪,把這個倉庫要做什麼整理成 SPEC.md。

小結 ​

  • Git 是改動記錄裝置,GitHub 是把這份記錄放在網際網路上協作的地方,倉庫是專案的家。
  • 免費帳號只有在公開倉庫裡才能使用 GitHub Pages。公開倉庫裡不要放個人資訊。
  • README 是說明書,.gitignore 是不上傳的清單,許可證是使用許可。.gitignore 要從一開始就寫好。
  • 克隆下來的副本與 GitHub 保持連線。

術語整理 ​

術語中文名稱一句話解釋
GitGit追蹤檔案改動的版本管理系統
GitHubGitHub把 Git 倉庫放在網際網路上協作的服務
READMEREADME倉庫的第一份說明書
.gitignore.gitignoreGit 要忽略的檔案清單
Clone克隆把倉庫連同記錄一起下載到我的電腦

這一章讀完了嗎?

學習記錄只儲存在這個瀏覽器中。整體進度可以在 全部目錄中檢視。

下一章:第3章. 策劃與規格

參考資料(18 則)
  1. GitHub 官方文件,《What is GitHub?》。"Git is a version control system that tracks changes to files." docs.github.com (確認日期 2026-11-01) ↩︎

  2. GitHub 官方文件,《Creating a repository for your project on GitHub》。"It stores your files, tracks each change as a commit, and gives collaborators a shared place to work." docs.github.com (確認日期 2026-11-01) ↩︎

  3. GitHub 官方文件,《About repositories》。"Branch | A parallel version of your code that is contained within the repository, but does not affect the primary or main branch." / "Merge | To take the changes from one branch and apply them to another." / "Remote | A repository stored on GitHub, not on your computer." docs.github.com (確認日期 2026-11-01) ↩︎

  4. GitHub 官方文件,《About repositories》。"Public repositories are accessible to everyone on the internet." / "Private repositories are only accessible to you, people you explicitly share access with, and, for organization repositories, certain organization members." docs.github.com (確認日期 2026-11-01) ↩︎

  5. GitHub 官方文件,《What is GitHub Pages?》。"GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server." docs.github.com (確認日期 2026-11-01) ↩︎

  6. GitHub 官方文件,《Creating a repository for your project on GitHub》。"Use the Choose visibility dropdown menu to select Public so you can publish your software project to a live site later in this series." docs.github.com (確認日期 2026-11-01) ↩︎

  7. GitHub 官方文件,《About repositories》。"Public repositories expose your codebase to everyone, increasing the risk that attackers might exploit vulnerabilities or access sensitive information." docs.github.com (確認日期 2026-11-01) ↩︎

  8. GitHub 官方文件,《Setting repository visibility》。"Any published GitHub Pages site will be automatically unpublished." docs.github.com (確認日期 2026-11-01) ↩︎

  9. GitHub 官方文件,《Creating a new repository》。"If you're importing an existing repository to GitHub, don't choose any of these options, as you may introduce a merge conflict." docs.github.com (確認日期 2026-11-01) ↩︎

  10. GitHub 官方文件,《About the repository README file》。"A README is often the first item a visitor will see when visiting your repository." docs.github.com (確認日期 2026-11-01) ↩︎

  11. GitHub 官方文件,《Creating a repository for your project on GitHub》。"Select Add README. This gives your repository a starting file and a place to describe your software project." docs.github.com (確認日期 2026-11-01) ↩︎

  12. GitHub 官方文件,《Ignoring files》。"You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit." docs.github.com (確認日期 2026-11-01) ↩︎

  13. GitHub 官方文件,《Ignoring files》。"If you want to ignore a file that is already checked in, you must untrack the file before you add a rule to ignore it." docs.github.com (確認日期 2026-11-01) ↩︎

  14. GitHub 官方文件,《Licensing a repository》。"A software license tells others what they can and can't do with your source code, so it's important to make an informed decision." / "However, without a license, the default copyright laws apply, meaning that you retain all rights to your source code and no one may reproduce, distribute, or create derivative works from your work." docs.github.com (確認日期 2026-11-01) ↩︎

  15. GitHub 官方文件,《Licensing a repository》。"We hope it helps, but please keep in mind that we’re not lawyers and that we make mistakes like everyone else." docs.github.com (確認日期 2026-11-01) ↩︎

  16. GitHub 官方文件,《Creating a new repository》。"If you're importing an existing repository to GitHub, don't choose any of these options, as you may introduce a merge conflict." docs.github.com (確認日期 2026-11-01) ↩︎

  17. GitHub 官方文件,《Connecting to your code locally》。"Cloning creates a copy of your repository on your computer that stays connected to the version on GitHub." docs.github.com (確認日期 2026-11-01) ↩︎

  18. GitHub 官方文件,《Adding locally hosted code to GitHub》。"If your locally-hosted code isn't tracked by any VCS, the first step is to initialize a Git repository." docs.github.com (確認日期 2026-11-01) ↩︎