Branching Strategy: Git Flow, GitHub Flow
Tujuan Pembelajaran
- Memahami strategi branching Git Flow
- Memahami strategi branching GitHub Flow
- Mengenal Trunk-Based Development
- Mampu memilih strategi yang tepat untuk project
Materi Inti
A. Git Flow (untuk Release Cycle Panjang)
Git Flow adalah strategi branching yang cocok untuk project besar dengan jadwal release terencana. Diciptakan oleh Vincent Driessen pada tahun 2010.
main --------*--------------------------*-------- (hanya release)
^ ^
release o--*--*--o o--*--o
^ ^ ^
develop *--*--*--*--*--*--*--*--*--*--*--*--*-- (integrasi)
^ ^ ^ ^ ^
feature *--* *--* *--* *--*
Branch dalam Git Flow:
| Branch | Fungsi | Lifetime |
|---|---|---|
main | Kode production yang stabil | Permanen |
develop | Integrasi semua fitur | Permanen |
feature/* | Pengembangan fitur baru | Sementara (merge ke develop) |
release/* | Persiapan release | Sementara (merge ke main + develop) |
hotfix/* | Perbaikan bug critical di production | Sementara (merge ke main + develop) |
Kapan cocok menggunakan Git Flow:
- Project dengan jadwal release tertentu (bulanan, quarterly)
- Tim besar dengan QA/testing terpisah
- Project enterprise yang membutuhkan release notes
Warning: Git Flow terlalu kompleks untuk project kecil atau tim yang deploy setiap hari. Jangan gunakan jika tidak perlu!
B. GitHub Flow (untuk Continuous Deployment)
GitHub Flow adalah strategi yang lebih sederhana, cocok untuk tim yang deploy sering (harian atau lebih).
main --*--*--*--*--*--*-- (selalu deployable)
^ ^ ^
feature *--* *--* *--*
PR PR PR
Aturan GitHub Flow:
- Branch
mainselalu dalam kondisi deployable - Buat feature branch dari main untuk setiap perubahan
- Commit dan push secara regular ke feature branch
- Buat Pull Request saat siap di-review
- Setelah di-review dan approved, merge ke main
- Deploy segera setelah merge
Tips: GitHub Flow adalah pilihan terbaik untuk kebanyakan project. Sederhana, efektif, dan mudah dipahami oleh semua anggota tim.
C. Trunk-Based Development
Strategi paling sederhana: semua developer commit langsung ke main (trunk). Fitur yang belum siap disembunyikan menggunakan feature flags.
main --*--*--*--*--*--*-- (semua commit di sini)
F F F
(feature flags)
Karakteristik:
- Tidak ada branch jangka panjang
- Commit langsung ke main atau branch sangat pendek (< 1 hari)
- Menggunakan feature flags untuk mengontrol fitur yang belum siap
- Cocok untuk tim yang sangat berpengalaman dengan CI/CD matang
Perbandingan Strategi
| Aspek | Git Flow | GitHub Flow | Trunk-Based |
|---|---|---|---|
| Kompleksitas | Tinggi | Rendah | Sangat rendah |
| Branch permanen | main + develop | main | main |
| Cocok untuk | Release terencana | Deploy sering | Deploy sangat sering |
| Ukuran tim | Besar | Kecil-menengah | Kecil-besar (berpengalaman) |
| CI/CD | Opsional | Disarankan | Wajib |
Demonstrasi Live: Simulasi GitHub Flow
mkdir proyek-tim && cd proyek-tim && git init
echo "# Proyek Tim" > README.md
git add . && git commit -m "Init project"
# Simulasi GitHub Flow - Fitur 1
git switch -c feature/halaman-about
echo "<h1>About Us</h1>" > about.html
git add . && git commit -m "feat: tambah halaman about"
git switch main && git merge feature/halaman-about
git branch -d feature/halaman-about
# Simulasi GitHub Flow - Fitur 2
git switch -c feature/halaman-contact
echo "<h1>Contact</h1>" > contact.html
git add . && git commit -m "feat: tambah halaman contact"
git switch main && git merge feature/halaman-contact
git branch -d feature/halaman-contact
# Simulasi GitHub Flow - Fitur 3
git switch -c feature/halaman-faq
echo "<h1>FAQ</h1>" > faq.html
git add . && git commit -m "feat: tambah halaman FAQ"
git switch main && git merge feature/halaman-faq
git branch -d feature/halaman-faq
# Lihat history yang rapi
git log --oneline --graph --all
Perhatikan pola: buat branch, kerjakan, merge, hapus branch, ulangi.
Latihan Interaktif
Latihan Terminal: Praktik GitHub Flow
Buat project website portfolio dengan 3 fitur menggunakan GitHub Flow:
mkdir portfolio && cd portfolio && git init
echo "# Portfolio" > README.md
echo "<!DOCTYPE html><html><body><h1>Portfolio</h1></body></html>" > index.html
git add . && git commit -m "init: setup project portfolio"
# Fitur 1: Halaman Skill
git switch -c feature/skills
echo "<section id='skills'>HTML, CSS, JS</section>" > skills.html
git add . && git commit -m "feat: tambah halaman skills"
git switch main && git merge feature/skills
git branch -d feature/skills
# Fitur 2: Halaman Project
git switch -c feature/projects
echo "<section id='projects'>Project 1, Project 2</section>" > projects.html
git add . && git commit -m "feat: tambah halaman projects"
git switch main && git merge feature/projects
git branch -d feature/projects
# Fitur 3: Halaman Kontak
git switch -c feature/contact
echo "<section id='contact'>Email: me@email.com</section>" > contact.html
git add . && git commit -m "feat: tambah halaman kontak"
git switch main && git merge feature/contact
git branch -d feature/contact
git log --oneline --graph
Tugas Mandiri
- Praktikkan GitHub Flow di 1 repo dengan minimal 3 fitur (buat branch, kerjakan, merge, hapus)
- Baca tentang Conventional Commits: https://www.conventionalcommits.org/
- Pikirkan: strategi branching mana yang paling cocok untuk project kamu? Mengapa?