建立、複製、提交、上傳 — Your First Repo
Repo(Repository)=專案倉庫,是 GitHub 上「一個專案」的容器。 它包含程式碼、版本歷史、Issue、PR、Wiki 等一切。可以是公開(人人可看)或私有。
1. 右上角「+」→ New repository 2. 填名稱(如 hello-world) 3. 選 Public / Private 4. 勾選 Add a README(建議) 5. 按 Create repository
把 repo 複製到自己的電腦開始開發。HTTPS 網址形如 https://github.com/使用者/repo名.git。
git clone https://github.com/you/hello-world.git cd hello-world
hello-world/ ├── .git/ # 版本歷史(隱藏) └── README.md # 專案檔案
Git 的日常循環只有三個步驟,全記住就夠了:
git add . # 1. 暫存(stage):挑選要納入的變更 git commit -m "說明" # 2. 提交(commit):存成一個版本快照 git push # 3. 推送(push):上傳到 GitHub
| 指令 | 作用 | 類比 |
|---|---|---|
git add | 把變更加入暫存區 | 打包要寄的東西 |
git commit | 存成一個帶說明的版本 | 寫郵戳寄出 |
git push | 把本地版本同步到 GitHub | 快遞送到雲端 |
fix: 修正登入頁空白;壞例子:update。
本地建立專案後要接上 GitHub(若你是先 clone 就略過):
git init -b main # 初始化,主分支叫 main git add . git commit -m "first commit" git remote add origin https://github.com/you/hello-world.git git push -u origin main # -u 記住 upstream,之後直接 git push
README 是訪客第一眼看到的文件(用 Markdown 寫——回顧我們的 Markdown 教學站)。
# hello-world A demo project. ## Usage ```bash npm start ``` ## License MIT
# 專案名:一級標題。
一句話簡介。
Usage:怎麼安裝、怎麼跑。
License:授權(單元 8 詳談)。
夠用的 README 就是這四段。
告訴 Git「哪些檔案不要追蹤」——例如 node_modules、建置產物、本機設定。
node_modules/ dist/ .env *.log .DS_Store
.env、金鑰、Token 務必加入 .gitignore——一旦 push 上去,
就進入了 Git 歷史,刪掉也還在歷史裡。