Start with GitLab.
Work like a developer.
เริ่มต้น GitLab
แบบที่ Developer ใช้งานจริง
A beginner-friendly hands-on workshop covering the essential GitLab workflow: repository, commit, branch, merge request, and pipeline. เวิร์กชอปสำหรับผู้เริ่มต้น เรียนรู้ workflow สำคัญของ GitLab ตั้งแต่ Repository, Commit, Branch, Merge Request ไปจนถึง Pipeline แบบลงมือทำจริง
Workshop Overviewภาพรวม Workshop
GitLab is more than a place to store code. It helps developers keep history, work safely in branches, review changes, and run automated checks before code is merged. GitLab ไม่ได้มีไว้แค่เก็บโค้ด แต่ช่วยให้ Developer เก็บประวัติการแก้ไข แยกงานด้วย Branch ตรวจงานผ่าน Merge Request และรันการตรวจสอบอัตโนมัติก่อน Merge
GitLab 101 — What is GitLab?GitLab 101 — GitLab คืออะไร?
GitLab is a DevSecOps platform built around Git. For this starter workshop, we focus on the core development workflow you will see in real software teams. GitLab คือแพลตฟอร์ม DevSecOps ที่ทำงานร่วมกับ Git สำหรับ Starter Workshop นี้ เราจะโฟกัสเฉพาะ workflow พื้นฐานที่พบในทีมพัฒนาซอฟต์แวร์จริง
Repository
The home of your project files and complete change history.พื้นที่เก็บไฟล์ของโปรเจกต์และประวัติการเปลี่ยนแปลงทั้งหมด
Commit
A saved checkpoint describing what changed in your project.จุดบันทึกการเปลี่ยนแปลง พร้อมข้อความอธิบายว่าแก้อะไร
Branch
A separate line of work that lets you change code without immediately touching main.พื้นที่ทำงานแยกจาก main เพื่อให้แก้โค้ดได้อย่างปลอดภัย
Merge Request
A place to review a change before bringing it back into main.พื้นที่สำหรับตรวจสอบการเปลี่ยนแปลงก่อนนำกลับเข้า main
Pipeline
Automated jobs that test or validate your code after a change.ชุดงานอัตโนมัติที่ใช้ตรวจสอบโค้ดหลังมีการเปลี่ยนแปลง
main
The primary branch that should contain the stable version of your project.Branch หลักที่ควรเก็บเวอร์ชันที่เสถียรของโปรเจกต์
Get Readyเตรียมความพร้อม
Before starting the labs, confirm that your GitLab account and local Git environment are ready. ก่อนเริ่ม Lab ให้ตรวจสอบว่า GitLab account และ Git บนเครื่องพร้อมใช้งาน
- GitLab.com account created and email verifiedมี GitLab.com account และ Verify email เรียบร้อย
- Able to sign in to GitLab.comสามารถ Sign in เข้า GitLab.com ได้
- Git installed on your laptopติดตั้ง Git บนเครื่องแล้ว
- Terminal available: PowerShell / Terminalมี Terminal ที่ใช้งานได้ เช่น PowerShell / Terminal
- A simple project folder containing index.htmlมีโฟลเดอร์โปรเจกต์ตัวอย่างที่มีไฟล์ index.html
Connect Kiro to GitLabเชื่อม Kiro กับ GitLab
Start with the project already open in Kiro, create an empty GitLab project, then connect your local folder to the remote repository. เริ่มจากโปรเจกต์ที่เปิดอยู่ใน Kiro สร้าง GitLab Project แบบว่าง แล้วเชื่อมโฟลเดอร์บนเครื่องเข้ากับ Remote Repository
Create and connect the repositoryสร้างและเชื่อม Repository
- Your work → Projects → Create new project → Create blank project on GitLab.com.Your work → Projects → Create new project → สร้าง Blank Project บน GitLab.com
- Visibility Level: Private เลือก Private
- Leave Initialize repository with a README unchecked.ไม่ต้องเลือก Initialize repository with a README
- Copy the HTTPS clone URL.Copy Clone URL แบบ HTTPS
- Open Terminal in the Kiro project folder and connect it to GitLab.เปิด Terminal ในโฟลเดอร์ Kiro แล้วเชื่อมเข้ากับ GitLab
git init git branch -M main git remote add origin <your GitLab HTTPS URL>
git remote add origin ... connects the local Git repository in your Kiro project to the remote repository on GitLab. origin is the name Git uses for that remote location.
git remote add origin ... คือการเชื่อม Local Git Repository ที่อยู่ใน Project ของ Kiro เข้ากับ Remote Repository บน GitLab โดย origin คือชื่อที่ Git ใช้เรียก Remote นี้
Verify the Kiro ↔ GitLab connectionตรวจสอบว่า Kiro ↔ GitLab เชื่อมกันแล้ว
Before committing or pushing anything, confirm that the correct GitLab remote has been configured. ก่อน Commit หรือ Push ให้ตรวจสอบก่อนว่า Local Project ชี้ไปยัง GitLab Repository ที่ถูกต้องแล้ว
git remote -v
You should see something similar to: ควรเห็นผลลัพธ์ประมาณนี้:
origin https://gitlab.com/username/project.git (fetch) origin https://gitlab.com/username/project.git (push)
Make Your First Commitสร้าง Commit แรก
Ask Kiro's AI to generate a README.md for the project, then use Source Control to review and save it as your first commit. ให้ AI ของ Kiro ช่วยสร้างไฟล์ README.md ให้กับโปรเจกต์ จากนั้นใช้หน้า Source Control เพื่อตรวจสอบและบันทึกเป็น Commit แรก
Prompt → Review → Commit
- Open Kiro's AI chat and run a prompt such as
Create a README.md file describing this project.เปิดหน้า AI Chat ของ Kiro แล้วรัน Prompt เช่นCreate a README.md file describing this project - Let Kiro generate
readme.mdand review the content it created.ปล่อยให้ Kiro สร้างไฟล์readme.mdแล้วอ่านตรวจสอบเนื้อหาที่ถูกสร้างขึ้น - Open Source Control and confirm
readme.mdappears as a new, untracked file.เปิด Source Control แล้วตรวจสอบว่ามีไฟล์readme.mdขึ้นเป็นไฟล์ใหม่ (untracked) - Review the diff before committing.ดู Diff ว่าแก้อะไรไปบ้างก่อน Commit
- Enter a message such as
Add README.mdand click the plain Commit button — this is your first commit.ใส่ข้อความ เช่นAdd README.mdแล้วกดปุ่ม Commit ธรรมดา — นี่คือ Commit แรกของคุณ - Check the project folder to confirm
readme.mdactually exists on disk and was included in the commit.ตรวจสอบโฟลเดอร์โปรเจกต์ว่ามีไฟล์readme.mdอยู่จริง และถูกรวมอยู่ใน Commit
git log --stat -1
git log --stat -1 shows the most recent commit and lists which files it includes — use it to confirm readme.md was really committed.
git log --stat -1 จะแสดง Commit ล่าสุดพร้อมรายชื่อไฟล์ที่อยู่ใน Commit นั้น ใช้เพื่อยืนยันว่า readme.md ถูก Commit ไปจริง
Push & Pull — Local Meets RemotePush & Pull — เมื่อ Local ทำงานร่วมกับ Remote
First push your local commit to GitLab. Then use GitLab Web IDE to simulate another developer changing the remote project, and pull that change back into Kiro. เริ่มจาก Push Commit จากเครื่องขึ้น GitLab จากนั้นใช้ GitLab Web IDE จำลองว่า Developer อีกคนเข้ามาแก้งานบน Remote แล้ว Pull การเปลี่ยนแปลงนั้นกลับลงมาใน Kiro
Send your commit to GitLabส่ง Commit ขึ้น GitLab
git push --set-upstream origin main
Simulate another developerจำลองว่ามี Developer อีกคนแก้งาน
- Open the same project in GitLab Web IDE.เปิด Project เดิมผ่าน GitLab Web IDE
- Pretend this browser session is Developer B.สมมติว่า Web IDE นี้คือ Developer B
- Change one obvious text value, for example a heading or footer.แก้ข้อความที่สังเกตเห็นง่าย เช่น Heading หรือ Footer
- Commit the change directly in Web IDE.Commit การเปลี่ยนแปลงผ่าน Web IDE
Bring the remote change back to Kiroดึง Change จาก GitLab กลับเข้า Kiro
git pull
- Return to Kiro.กลับมาที่ Kiro
- Run
git pull.รันgit pull - Open the HTML file again and find the text changed in Web IDE.เปิดไฟล์ HTML แล้วหา Text ที่เพิ่งแก้จาก Web IDE
BranchBranch
Learn why developers avoid changing main directly and how a branch creates a safe workspace.เรียนรู้ว่าทำไม Developer ไม่ควรแก้ main โดยตรง และ Branch ช่วยแยกพื้นที่ทำงานอย่างไร
Create a feature branchสร้าง Feature Branch
- In Kiro, click the branch name in the bottom-left status bar (or open Source Control → Branches).ใน Kiro คลิกชื่อ Branch ที่มุมล่างซ้าย (หรือเปิด Source Control → Branches)
- Choose Create new branch and name it
update-homepage, created frommain.เลือก Create new branch แล้วตั้งชื่อupdate-homepageโดยแตกจากmain - Edit a small part of
index.html.แก้ไขข้อความเล็กน้อยในไฟล์index.html - Review the diff.ดู Diff ว่าแก้อะไรไปบ้าง
- Commit with a clear message such as
Update homepage title.ใส่ข้อความ เช่นUpdate homepage titleแล้ว Commit
git checkout -b update-homepage
update-homepage keeps main untouched until the change is reviewed. Push and Merge Request come next.
การทำงานบน update-homepage ทำให้ main ไม่ถูกแก้ไขจนกว่าจะผ่านการ Review ขั้นต่อไปคือ Push แล้วสร้าง Merge Request
Merge RequestMerge Request
A Merge Request lets you compare, discuss, and review a branch before merging it into main.Merge Request ใช้สำหรับเปรียบเทียบ ตรวจสอบ และ Review การเปลี่ยนแปลงก่อน Merge เข้า main
Open, review, and merge your changeเปิด Review และ Merge งานของคุณ
- Push your branch to GitLab first:
git push --set-upstream origin update-homepage(or click Sync/Publish Branch in Kiro).Push Branch ขึ้น GitLab ก่อน:git push --set-upstream origin update-homepage(หรือกด Sync/Publish Branch ใน Kiro) - On GitLab, go to Code → Merge requests → New merge request.บน GitLab ไปที่ Code → Merge requests → New merge request
- Set Source branch =
update-homepageand Target branch =main. Double-check this order — swapping them is the most common mistake.ตั้งค่า Source branch =update-homepageและ Target branch =mainตรวจสอบลำดับให้ดี — สลับผิดคือข้อผิดพลาดที่พบบ่อยที่สุด - Click Compare branches and continue.กด Compare branches and continue
- Enter a Title such as
Update homepage, then click Create merge request.ใส่ Title เช่นUpdate homepageแล้วกด Create merge request - Open the Changes tab and check exactly what lines were added or removed.เปิดแท็บ Changes แล้วตรวจว่าบรรทัดไหนถูกเพิ่ม/ลบ
- Confirm the change is what you intended, then continue to LAB 07 before merging.ตรวจว่าตรงกับที่ตั้งใจแก้ แล้วไปทำ LAB 07 ต่อก่อนจะ Merge
main into update-homepage" instead of "update-homepage into main", the branches are reversed. Close it and create a new one in the correct direction — do not merge it.
ถ้าหัว MR เขียนว่า "main into update-homepage" แทนที่จะเป็น "update-homepage into main" แปลว่าตั้งค่า branch กลับด้าน ให้ปิด MR นั้นทิ้ง แล้วสร้างใหม่ให้ถูกทิศทาง อย่ากด Merge
!1) to open the existing one instead of creating a new one.
GitLab จะไม่ให้เปิด MR ซ้ำสำหรับ branch คู่เดิม ถ้าเห็นข้อความ "already have an open merge request" ให้กดหมายเลข (เช่น !1) เพื่อเปิด MR เดิมแทนการสร้างใหม่
Your First PipelinePipeline แรกของคุณ
A pipeline runs automated jobs. For this starter lab, we only check whether index.html exists.Pipeline ใช้รันงานแบบอัตโนมัติ ใน Lab นี้เราจะเริ่มง่าย ๆ ด้วยการตรวจว่าไฟล์ index.html มีอยู่จริง
.gitlab-ci.yml
stages:
- test
check-html:
stage: test
image: alpine:latest
script:
- test -f index.html
- echo "index.html found"
- Create
.gitlab-ci.ymlon your feature branch (the same one from LAB 06). - Commit the file — this updates the open Merge Request automatically.
- Open the Merge Request and watch the pipeline run.
- Wait for the pipeline to show Passed.
- Continue to LAB 08 to add the deploy job — do not merge yet.ไปทำ LAB 08 ต่อเพื่อเพิ่ม Deploy Job ก่อน — ยังไม่ต้อง Merge
Deploy with GitLab PagesDeploy เว็บด้วย GitLab Pages
After the CI checks pass and the change is merged into main, publish the static website with GitLab Pages. หลังจาก CI ตรวจสอบผ่านและ Merge Change เข้า main แล้ว ให้ Publish Static Website ด้วย GitLab Pages
From repository to live websiteจาก Repository สู่เว็บไซต์ที่เปิดใช้งานได้
stages:
- test
- deploy
check-html:
stage: test
image: alpine:latest
script:
- test -f index.html
- echo "index.html found"
deploy-pages:
stage: deploy
image: alpine:latest
script:
- mkdir -p public
- cp index.html public/index.html
pages: true
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
- Update
.gitlab-ci.ymlwith the deploy job above, on the same feature branch from LAB 06/07.ปรับ.gitlab-ci.ymlโดยเพิ่ม Deploy Job ด้านบน บน Feature Branch เดิมจาก LAB 06/07 - Commit the change — the same open Merge Request updates automatically.Commit Change — Merge Request เดิมที่เปิดอยู่จะอัปเดตให้อัตโนมัติ
- Wait for the CI check to pass, then merge into
main(this is the only merge for this feature).รอ CI Check ผ่าน แล้ว Merge เข้าmain(Merge แค่ครั้งเดียวสำหรับงานนี้) - The pipeline on main runs again and executes the GitLab Pages deployment.Pipeline บน main จะรันอีกรอบและทำ GitLab Pages Deployment
- Open Deploy → Pages and open the generated website URL.ไปที่ Deploy → Pages แล้วเปิด Website URL ที่ระบบสร้างให้
.gitlab-ci.yml and can commit it directly to main, which conflicts with the file you're editing here and breaks the pipeline. Edit .gitlab-ci.yml yourself in Kiro instead — never through that wizard.
Wizard Deploy → Pages → "Get started with GitLab Pages" ของ GitLab จะสร้าง .gitlab-ci.yml เวอร์ชันของตัวเอง และอาจ commit ตรงเข้า main ทันที ซึ่งจะขัดแย้งกับไฟล์ที่เราแก้อยู่และทำให้ Pipeline พัง ให้แก้ .gitlab-ci.yml เองใน Kiro เท่านั้น อย่าใช้ Wizard นี้
Starter Troubleshootingแก้ปัญหาเบื้องต้น
Common errors you may see during your first GitLab workflow.Error ที่มักพบเมื่อเริ่มใช้งาน GitLab ครั้งแรก
remote origin already exists
git remote set-url origin <your GitLab HTTPS URL>
Permission denied (publickey)
You copied an SSH URL. Use the HTTPS clone URL instead.คุณ Copy URL แบบ SSH มา ให้เปลี่ยนไปใช้ Clone URL แบบ HTTPS
nothing to commit, working tree clean
There is no new change to commit. You can continue to the next step.ไม่มี Change ใหม่ให้ Commit สามารถไปขั้นตอนถัดไปได้
Browser sign-in does not appear
Check the taskbar, confirm your default browser, then retry git push.ตรวจ taskbar และ default browser แล้วลอง git push ใหม่
What You Will Learnเมื่อจบ Workshop คุณจะทำอะไรได้บ้าง
- Explain what GitLab is and how it fits into a developer workflowอธิบายได้ว่า GitLab คืออะไร และอยู่ตรงไหนใน workflow ของ Developer
- Create a GitLab repository and push code from your laptopสร้าง Repository และ Push โค้ดจากเครื่องขึ้น GitLab ได้
- Use commits to keep a history of changesใช้ Commit เพื่อเก็บประวัติการเปลี่ยนแปลงได้
- Explain and demonstrate Push (Local → Remote) and Pull (Remote → Local)อธิบายและทดลอง Push (Local → Remote) และ Pull (Remote → Local) ได้
- Create a branch and work without directly changing mainสร้าง Branch และทำงานโดยไม่แก้ main โดยตรงได้
- Open and review a Merge Requestเปิดและ Review Merge Request ได้
- Understand what a pipeline does and read a basic CI resultเข้าใจว่า Pipeline ทำอะไร และอ่านผล CI พื้นฐานได้
- Deploy a static website with GitLab Pages and open its published URLDeploy Static Website ด้วย GitLab Pages และเปิด URL ของเว็บไซต์ที่ Publish แล้วได้