Waktu pertama kali kerja di tim yang lebih dari 3 orang, saya langsung kena masalah branch conflict setiap hari. Ada yang push ke main, ada yang bikin branch namanya asal-asalan, dan merge conflict jadi rutinitas pagi. Setelah coba beberapa strategi, barulah saya paham bahwa pilihan git workflow itu ngaruh banget ke produktivitas tim.
Di artikel ini, saya mau share pengalaman pakai tiga workflow paling populer: Git Flow, GitHub Flow, dan Trunk-Based Development. Masing-masing punya kelebihan, dan pilihan yang tepat tergantung jenis project dan ukuran tim kamu.
Bayangkan kamu kerja bareng 5 orang developer. Tanpa aturan yang jelas soal branching, setiap orang punya cara sendiri. Ada yang langsung commit ke main, ada yang bikin 20 branch tapi nggak pernah merge, ada yang force push dan menghilangkan kerja orang lain.
Git workflow itu basically aturan main untuk tim kamu. Siapa yang boleh merge ke main? Branch apa saja yang wajib ada? Kapan saatnya release? Semua ini diatur oleh workflow yang kamu pilih.
Git Flow dipopulerkan oleh Vincent Driessen tahun 2010. Workflow ini punya branch yang cukup banyak dan aturan yang ketat soal kapan setiap branch boleh dibuat dan di-merge.
Branch utama di Git Flow:
Cara pakai Git Flow:
# Install git-flow (Ubuntu/Debian)
sudo apt install git-flow
# Inisialisasi di repo yang sudah ada
git flow init
# Bikin fitur baru
git flow feature start user-authentication
# Selesai develop fitur, merge ke develop
git flow feature finish user-authentication
# Persiapan release
git flow release start v2.1.0
# Release selesai, merge ke main dan develop
git flow release finish v2.1.0
# Hotfix urgent
git flow hotfix start critical-login-bug
git flow hotfix finish critical-login-bug
Contoh manual tanpa git-flow CLI:
# Mulai dari develop
git checkout develop
git pull origin develop
# Bikin feature branch
git checkout -b feature/payment-gateway
# Kerja di feature branch...
git add .
git commit -m "feat: integrate Midtrans payment"
# Merge balik ke develop
git checkout develop
git merge --no-ff feature/payment-gateway
git push origin develop
# Hapus feature branch
git branch -d feature/payment-gateway
Kelebihan Git Flow:
Kekurangan Git Flow:
GitHub Flow jauh lebih simple dibanding Git Flow. Hanya ada satu branch utama (main) dan feature branches. Kalau fitur sudah siap, bikin Pull Request, review, merge, deploy. Gitu aja.
# Selalu mulai dari main
git checkout main
git pull origin main
# Bikin branch baru
git checkout -b add-search-feature
# Commit perubahan
git add .
git commit -m "feat: add full-text search to product page"
# Push ke remote
git push origin add-search-feature
# Buka Pull Request di GitHub
# Setelah review dan approve, merge ke main
# Deploy otomatis dari main
Aturan GitHub Flow:
Contoh workflow di team:
# Developer A: bikin fitur baru
git checkout main && git pull
git checkout -b feature/user-dashboard
# ... kerja ...
git push origin feature/user-dashboard
# Buka PR di GitHub
# Developer B: review PR
git fetch origin
git checkout feature/user-dashboard
# Review code di IDE atau di GitHub UI
# Kasih comment atau approve
# Developer A: merge setelah approve
# Klik "Merge pull request" di GitHub
# Branch otomatis terhapus
Kelebihan GitHub Flow:
Kekurangan GitHub Flow:
Trunk-Based Development (TBD) adalah workflow di mana semua developer commit langsung ke satu branch utama (trunk/main). Feature branches kalau ada pun sangat pendek, maksimal 1-2 hari.
Konsep utama:
# Developer langsung commit ke main
git checkout main
git pull origin main
# ... kerja ...
git add .
git commit -m "feat: add cart sidebar component"
git push origin main
# Atau pakai branch pendek
git checkout -b quick-fix-header
# ... fix ...
git checkout main
git merge quick-fix-header
git push origin main
Feature flags di practice:
// config/feature-flags.js
const featureFlags = {
newCheckoutFlow: process.env.FF_NEW_CHECKOUT === 'true',
darkMode: process.env.FF_DARK_MODE === 'true',
betaSearch: false, // belum siap
};
// Di component
if (featureFlags.newCheckoutFlow) {
renderNewCheckout();
} else {
renderOldCheckout();
}
<?php
// Feature flag di PHP
class FeatureFlags {
public static function isEnabled(string $flag): bool {
$flags = [
'new_dashboard' => env('FF_NEW_DASHBOARD', false),
'ai_search' => env('FF_AI_SEARCH', false),
];
return $flags[$flag] ?? false;
}
}
// Di controller
if (FeatureFlags::isEnabled('new_dashboard')) {
return view('dashboard/v2');
}
return view('dashboard/v1');
Kelebihan Trunk-Based:
Kekurangan Trunk-Based:
| Aspek | Git Flow | GitHub Flow | Trunk-Based |
|---|---|---|---|
| Jumlah branch | Banyak (5+ tipe) | Sedikit (main + feature) | Sangat sedikit (main) |
| Deploy frequency | Per release cycle | Setiap merge ke main | Bisa beberapa kali sehari |
| Complexity | Tinggi | Rendah | Sedang (butuh feature flags) |
| Tim ideal | Besar, enterprise | Kecil-sedang, startup | Mature, DevOps-heavy |
| Learning curve | Sedang | Rendah | Tinggi |
| Merge conflict | Sering | Jarang | Hampir nggak ada |
Apapun workflow yang kamu pilih, ada beberapa best practice yang wajib diterapkan:
1. Commit message yang jelas
# BAD
git commit -m "fix"
git commit -m "update"
git commit -m "changes"
# GOOD - pakai conventional commits
git commit -m "feat: add user registration with email verification"
git commit -m "fix: resolve null pointer on empty cart checkout"
git commit -m "refactor: extract payment logic to service class"
git commit -m "docs: update API endpoint documentation"
2. Branch naming convention
# Format: type/short-description
feature/user-auth
feature/payment-integration
bugfix/login-redirect
hotfix/security-patch-xss
chore/update-dependencies
docs/api-documentation
3. Lindungi main branch
# Di GitHub: Settings > Branches > Branch protection rules
# Checklist:
# - Require pull request reviews before merging
# - Require status checks to pass (CI must be green)
# - Require branches to be up to date before merging
# - Include administrators (jangan bypass aturan sendiri)
4. Rebase vs Merge
# Merge: commit history bercabang
git checkout main
git merge feature-branch
# Result: commit history bercabang, ada merge commit
# Rebase: commit history linear
git checkout feature-branch
git rebase main
git checkout main
git merge feature-branch
# Result: commit history linear, lebih rapi
# Interactive rebase untuk clean up commit
git rebase -i HEAD~3
# Bisa squash, reword, atau drop commit
5. Git bisect untuk cari bug
# Mulai bisect
git bisect start
# Tandai commit yang broken
git bisect bad
# Tandai commit yang masih bagus
git bisect good v2.0.0
# Git akan checkout commit di tengah
# Test, lalu tandai sebagai good atau bad
git bisect good # atau
git bisect bad
# Ulangi sampai ketemu commit yang bikin bug
# Git kasih output:
# abc1234 is the first bad commit
# Selesai
git bisect reset
Berdasarkan pengalaman saya, kebanyakan tim dev di Indonesia pakai GitHub Flow karena:
Kalau kamu kerja di startup atau agency, mulai dengan GitHub Flow. Kalau sudah matang dan punya CI/CD yang solid, baru pertimbangkan Trunk-Based. Git Flow lebih cocok untuk perusahaan besar yang punya QA team dan release schedule.
Tidak ada workflow yang paling benar. Yang paling penting adalah konsistensi. Lebih baik pakai GitHub Flow secara konsisten daripada pakai Git Flow tapi nggak pernah ngikutin aturannya. Pilih workflow yang sesuai dengan ukuran tim, jenis project, dan culture kerja tim kamu.
Kalau baru mulai, saran saya: pakai GitHub Flow dulu. Simple, gampang dipelajari, dan cocok untuk mayoritas project web development. Setelah tim makin besar dan proses makin matang, baru evaluate apakah perlu pindah ke Git Flow atau Trunk-Based Development.