建立、clone、push、Group 群組
GitLab 不用「Repository」,改用專案(Project)與群組(Group):
| GitLab 術語 | GitHub 對應 | 說明 |
|---|---|---|
| Project(專案) | Repository | 程式碼+Issues+CI+Pages 的容器 |
| Group(群組) | Organization | 組織多個專案、集中管理權限與共用 Runner |
| Subgroup(子群組) | —(GitHub 無對等) | 群組可巢狀,做出組織樹 |
| Namespace(命名空間) | owner 名 | 專案路徑的第一段:group/project 或 user/project |
gitlab.com/team-ai/backend/api-gw 中,
team-ai 是 Group,backend 是 Subgroup,api-gw 才是 Project。1. 右上角「+」→ New project → Create blank project 2. Project name:hello-world(自動生成 slug) 3. Visibility:Private(先選這個,可事後改) 4. 勾選 Initialize repository with a README 5. 可選 .gitignore 樣板、LICENSE 樣板 6. Create project
Public 以為無所謂——
程式碼會公開給全世界(含未登入者)。不確定就先 Private,之後隨時可改。git clone https://gitlab.com/USER/hello-world.git
cd hello-world
git remote -v # 確認 originhello-world/ ├── .git/ # 版本歷史(本地) └── README.md # 剛勾選產生的檔案
Git 的日常循環與 GitHub 完全一樣(Git 是同一套工具):
git add . git commit -m "說明這次改動" git push
git log --oneline 一眼看懂歷史,未來的人(包括三個月後的你)會感謝你。本機已經有專案、GitLab 上只有空白專案時:
cd /path/to/my-app git init -b main # 或 git init 後 git branch -M main git add . git commit -m "first commit" git remote add origin https://gitlab.com/USER/hello-world.git git push -u origin main # -u 記憶 upstream,之後直接 git push
git@gitlab.com:...git)
或確認 PAT scope 勾了 write_repository,而不是把 URL 改來改去。多個專案該放進群組管理:
左上角選單 → Groups → New group
├── Group name:my-company
└── 建立後可在 Groups 內再建 Subgroup
(如 my-company / frontend)
把既有專案移入:Project → Settings → General
→ Advanced → Transfer project → 選群組
| 權限角色 | 能幹嘛(由高到低) |
|---|---|
| Owner | 群組一切管理、刪除 |
| Maintainer | 管理專案設定、合併權限、CI/CD 設定 |
| Developer | push、開 MR、跑 pipeline(日常開發主力) |
| Reporter | 唯讀+回報 issue |
| Guest | 只能看 issue 等最小權限 |
| 層級 | 誰能看到 | 建議用途 |
|---|---|---|
| Private | 只有專案成員 | 預設值、公司內部專案 |
| Internal | 登入此 GitLab 實例的人 | 自架環境「全公司可見」 |
| Public | 任何人(含未登入) | 開源專案、作品集 |
自架 GitLab 時 Internal 超好用:整個公司可看,公司外看不到——GitHub 沒有這個層級。
1. 建立私有專案 demo-app(含 README) 2. clone 到本機 3. 新增 hello.py 4. commit + push 5. 在網頁確認檔案出現
✅ git clone 成功
✅ git push 成功
✅ 網頁 Files 頁看到 hello.py
✅ git log --oneline 有兩筆 commit
✅ git remote -v 指向 gitlab.com
git remote add 方式把一個既有資料夾推到 GitLab。一個 15 人團隊,需要三個專案(前端、後端、共用函式庫),全部放在同一個群組下,共用一組自架 Runner。
myorg/ ← Group ├── frontend-app ← Project(Visibility: Private) ├── backend-api ← Project(Visibility: Private) ├── shared-ui-lib ← Project(Visibility: Internal,全公司可讀) └── myorg.gitlab.io ← Project(Visibility: Public,對外入口) # Group Runner 註冊(在群組設定頁取得 token) sudo gitlab-runner register \ --url https://gitlab.example.com \ --token <GROUP_TOKEN> \ --executor docker \ --tag-list "myorg" \ --run-untagged="false" # 權限設計: # Owner → 技術主管(2人) # Maintainer → Team Lead(3人) # Developer → 開發者(10人)
GitLab 的 URL 路徑對應到內部的 Namespace(命名空間)。一個專案的完整路徑是 namespace/project,其中 namespace 可以是 User 或 Group。
| URL 路徑 | Namespace 類型 | 專案歸屬 |
|---|---|---|
| gitlab.com/alice/hello | User(alice) | 個人專案 |
| gitlab.com/myorg/backend-api | Group(myorg) | 群組專案 |
| gitlab.com/myorg/platform/backend-api | Subgroup(myorg/platform) | 子群組專案 |
| 症狀 | 可能原因 | 解決方案 |
|---|---|---|
| git push 顯示「remote: The project you were looking for could not be found」 | 遠端 URL 路徑錯誤(例如群組名拼錯) | 執行 git remote -v 確認 URL,用 git remote set-url origin 修正 |
| 看不到 Internal 專案 | 你在 GitLab.com(非自架),或帳號未登入 | Internal 只在自架環境有效;確認已登入該 GitLab 實例 |
| Subgroup 裡的專案權限不符預期 | Subgroup 有獨立的權限設定,覆蓋了上層 Group 的繼承 | 檢查 Subgroup → Members,確認是否有人為覆寫 |
| git clone 报 SSL certificate problem | 自架 GitLab 使用自簽憑證,本機不信任 | 執行 git config --global http.sslVerify false(開發用),或匯入公司 CA 憑證 |
| 專案路徑中有大寫字母被拒絕 | GitLab slug 只允許小寫英文、數字、連字號、底線 | 專案名稱可含大寫,但路徑 slug 會自動轉小寫;建專案時直接用小寫命名 |
公司成立「平台」與「產品」兩條產品線,需要一次建好群組樹、權限矩陣與 Visibility 策略,讓 20 人團隊各自安全進場。
my-company/ ← Group(Private) ├── platform/ ← Subgroup:平台工程 │ ├── api-gateway/ ← Project(Private) │ ├── user-service/ ← Project(Private) │ └── shared-libs/ ← Project(Internal) ├── product/ ← Subgroup:產品開發 │ ├── web-app/ ← Project(Private) │ └── mobile-app/ ← Project(Private) └── my-company.gitlab.io/ ← Project(Public)對外入口(單元 7)
# .gitignore(每個新專案起手式,防密鑰入庫) .env *.pem *.key node_modules/ dist/ .DS_Store # .gitlab-ci.yml(每個專案最基礎的 CI,單元 6) stages: [test] hello: stage: test script: echo "Hello from $CI_PROJECT_PATH"
$ git remote -v
origin git@gitlab.example.com:my-company/platform/api-gateway.git
$ glab api "groups/my-company" 2>/dev/null | head -c 300
{"id":7,"name":"my-company","visibility":"private",...}
$ git push -u origin main # 首次推送後,網頁看到 pipeline 綠燈
To gitlab.example.com:my-company/platform/api-gateway.git
* [new branch] main -> main
git gc,必要時用 git filter-repo 清掉誤入的大檔與敏感檔。group/project-templates 統一規範。| 面向 | gitlab | github | markdown | yaml | json |
|---|---|---|---|---|---|
| 程式碼容器 | Project(含 CI/Issues/Pages) | Repository(repo 為主) | .md 文件 | .yml 設定 | .json 資料 |
| 組織單位 | Group / Subgroup(巢狀) | Organization(單層) | — | — | — |
| 可見性 | Private / Internal / Public | Private / Public(無 Internal) | 由平台檔案權限決定 | 同左 | 同左 |
| 權限角色 | Owner→Maintainer→Developer→Reporter→Guest | Owner→Admin→Write→Read | — | — | — |
| 建立方式 | New project + 樣板 | New repository + 樣板 | 任何編輯器寫檔 | 任何編輯器寫檔 | 程式/編輯器產生 |
- [ ] 已建立 Group + Subgroup,並畫出權限矩陣 - [ ] 每個專案都有 README / LICENSE / CHANGELOG / .gitignore - [ ] visibility 全部核對:內部專案 Private、對外專案 Public - [ ] 用 Guest 帳號實測:讀不到 Private 專案、看得到 Internal 專案 - [ ] repo 內無 .env / 憑證;密鑰全部在 CI Variables - [ ] 已 push 至少一個專案並看到 pipeline 綠燈