Git Flow 01 – Intro

Ada beberapa metode branching Git yang bisa kita praktekin. Ada model Centralized, Environment Branching, dan lain-lain. Git Flow adalah salah satu yang populer.

Di dalam metode Git-Flow, ada dua long-lived branch (cabang yang ga pernah dihapus) yaitu:
master
develop

master berisi kode yang di-deploy ke production-server. Jadi hanya kode yang sudah dites, lolos QA & dirilis yang ada di sini.

develop, sesuai namanya, dipake untuk development. Untuk sinkronisasi kode antara satu developer dengan yang lain. Penambahan fitur baru atau perbaikan kode selalu berbasis branch ini.

Instalasi

Ini opsional, kita bisa pake metode Git Flow pake perintah-perintah standar Git, tanpa command-line tool tapi rawan error karena lupa, dll. Jadi mending instal CLI-nya.

Ada dua macam CLI yang populer, satu yang Git Flow yg asli/vanilla & yg satu fork-nya git-flow-avh. Versi AVH lebih baru daripada yg vanilla & ada beberapa perintah tambahan.

  • Windows: git-flow-avh udah termasuk di dalam paket Git for Windows. Kalo pake Chocolatey, choco install git.
  • Mac: brew install git-flow-avh
  • Linux: di sini.

Inisiasi Local Repo

Alih-alih pake command git init, kita pake git flow init -d. Flag -d artinya pake opsi default.

$ git flow init -d
Initialized empty Git repository in /Volumes/workspace/personal/gitflow-example/.git/
Using default branch names.
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
Hooks and filters directory? [/Volumes/workspace/personal/gitflow-example/.git/hooks]

Perintah di atas bikin dua branch yaitu master dan develop, terus otomatis bikin Initial commit.

$ git log
commit 2789c4b673bb5b2632998a8cd2a14392677229e1 (HEAD -> develop, master)
Author: Anggie Bratadinata <anggie.bratadinata@gmail.com>
Date:   Sun Nov 19 22:38:40 2017 +0700

    Initial commit

Nggak hanya itu, develop otomatis di-checkout.

$ git branch
* develop
  master

Bikin Fitur Baru

Fitur baru kita kerjain di cabang yang disebut feature-branch. Misalnya kita ingin mulai mengerjakan fitur baru bernama Feat-A, kita jalanin perintah:

$ git flow feature start Feat-A
Switched to a new branch 'feature/Feat-A'

Summary of actions:
- A new branch 'feature/Feat-A' was created, based on 'develop'
- You are now on branch 'feature/Feat-A'

Now, start committing on your feature. When done, use:

     git flow feature finish Feat-A

Jadi perintah di atas bikin cabang baru feature/Feat-A & otomatis checkout.

Push Feature Branch untuk Review / PR

Setelah bikin update di branch feature/Feat-A, jangan langsung jalanin perintah git flow feature finish, karena perintah itu langsung merge feature/Feat-A ke develop. Kita ingin pake proses code-review & pull request, jadi kita push dulu branch ini ke origin.

$ git flow feature publish
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 812 bytes | 812.00 KiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for feature/Feat-A, visit:
remote:   https://gitlab.com/masputih/gitflow-example/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2FFeat-A
remote:
To gitlab.com:masputih/gitflow-example.git
 * [new branch]      feature/Feat-A -> feature/Feat-A
Branch feature/Feat-A set up to track remote branch feature/Feat-A from origin.
Already on 'feature/Feat-A'
Your branch is up-to-date with 'origin/feature/Feat-A'.

Summary of actions:
- The remote branch 'feature/Feat-A' was created or updated
- The local branch 'feature/Feat-A' was configured to track the remote branch
- You are now on branch 'feature/Feat-A'

Di sini saya pake Gitlab, kalo pake hosting lain mungkin output terminalnya sedikit beda.

Setelah push selesai, kita bikin PR lewat web.

Ingat : Karena feature/Feat-A asalnya dari develop, kita bikin PR ke develop.

Di Gitlab namanya bukan Pull Request, tapi Merge Request

PR

Reviewer bisa checkout feature/Feat-A dengan perintah:

git flow feature track Feat-A

Setelah code-review selesai, reviewer bisa merge lewat web atau local di komputernya pake perintah

git flow feature finish Feat-A

Terus dilanjutin update origin/develop.

git push develop

Setelah itu si committer (developer yang bikin ngerjain Feat-A) bisa menghapus feature/Feat-A di repo lokalnya. Karena udah di-merge ke develop & ga dipake lagi.

Dah segini aja dulu biar nggak kepanjangan. Silakan lanjut ke Bagian 2 tentang Release Branch.

Also in this category ...


Leave a Reply

Your email address will not be published. Required fields are marked *