Git Flow

ဒီနေ့တော့ ကျွန်တော် git flow အကြာင်းကို ရေးသွားမှာပါ။ အားလုံးသိတဲ့ အတိုင်း git ဆိုတာ version control system တွေအတွက်သုံးတဲ့ command line tool တစ်ခုဖြစ်ပါတယ်။ git flow ဆိုတာက git branch တွေကို logical ကျကျ manage လုပ်ဖို့သုံးတဲ့ branching model တစ်ခုဖြစ်ပါတယ်။ main branch ကိုလုံးဝမထိပဲ develop branch ကနေပဲ အခြား supporting branches တွေဖြစ်တဲ့ feature branches ၊ release branches ၊ hotfix branches တွေကို manage လုပ်သွားမှာဖြစ်ပါတယ်။ အဓိက target ကတေ့ာ main branch ထဲမှာ production-read code တွေကိုပဲ ထားဖို့ပါ။

👉 Install Git Flow

git flow ကို window ၊ linux ၊ mac OS အကုန်လုံးမှာ install လုပ်နိုင်ပါတယ်။ ubuntu မှာတော့ အောက်ကအတိုင်း install လုပ်နိုင်ပါတယ်။

sudo apt update -y
sudo apt install git-flow -y

👉 Main & Develop Branches

git flow က project ရဲ့ history ကို main branch နဲ့ develop branch ၂ခုလုံးမှာ store လုပ်သွားမှာပါ။ main branch ကတော့ official release history ကိုပဲ သိမ်းမှာဖြစ်ပြီး develop branch ကတော့ တစ်ခြား feature branches တွေအတွက် integration branch အနေနဲ့ လုပ်ဆောင်ပေးသွားမှာပါ။ git flow အကြောင်းကိုပိုမြင်သွားအောင် lab လေးတစ်ခုနဲ့ တွဲရှင်းပြလိုက်ပါမယ်။ အရင်ဆုံး directory တစ်ခုဆောက်လိုက်ပါမယ်။

mkdir gitflow-demo
cd gitflow-demo

ဒါဆိုရင် create ခဲ့တဲ့ dir ထဲမှာ git flow init နဲ့ initialize စလုပ်ပါမယ်။ branch တွေကို NAME ပေးရပါမယ်။ production အတွက် branch ကို main လို့ပေးပြီး development လုပ်မယ့် branch ကို develop လို့ပေးလိုက်ပါတယ်။ ကျန်တာကိုတော့ default ပဲထားလိုက်ပါတယ်။

Initialized empty Git repository in /home/thaunghtikeoo/gitflow-demo/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master] main
Branch name for "next release" development: [develop] 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? [/home/thaunghtikeoo/gitflow-demo/.git/hooks]

အခုချိန်မှာ git branch နဲ့ ကြည့်လိုက်ရင် develop branch ကိုရောက်နေတာကိုတွေ့ရမှာဖြစ်ပါတယ်။ feauture branches တွေကို develop branch ကနေပဲ integrate လုပ်သွားမှာဖြစ်ပါတယ်။

👉 Feature Branch

feature branch ဆိုတာက app အတွက်လိုအပ်တဲ့ feature တစ်ခုစီအတွက် feature branch တစ်ခုသက်သက် ခွဲပေးထားတာပါ။ login feature အတွက် သုံးမယ့် code တွေကို feature/login ဆိုတဲ့ branch ထဲမှာ သိမ်းပါမယ်။ feature က branch type ကိုဆိုလိုတာပါ။ ဒါဆိုအခု feature branch တစ်ခု create ပါမယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflow-demo$ git flow feature start login
Switched to a new branch 'feature/login'

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

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

     git flow feature finish login

login feature branch တစ်ခု create ပြီးပြီဆိုတော့ git branch နဲ့ကြည့်လိုက်ရင် login branch ထဲမှာ ရောက်နေတာကိုတွေ့ရမှာဖြစ်ပါတယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflow-demo$ git branch
  develop
* feature/login
  main

login feature မှာထည့်မယ့် file အချို့ကို create ပေးလိုက်ပါမယ်။ testing ဆိုတော့ file လေးတွေပဲ create လိုက်ပါမယ်။

touch index.html demo

login feature ထဲမှာ ထည့်မယ့် code တွေအကုန်သေချာသွားပြီဆိုရင် finish လိုက်ပါမယ်။ finish လုပ်တဲ့အခါမှာ login branch က delete လုပ်သွားမှာဖြစ်ပြီး develop နဲ့ main branch တွေကို merge လုပ်သွားမှာပါ။

thaunghtikeoo@thaunghtikeoo:~/gitflow-demo$ git flow feature finish login
Switched to branch 'develop'
Already up to date.
Deleted branch feature/login (was 9228482).

Summary of actions:
- The feature branch 'feature/login' was merged into 'develop'
- Feature branch 'feature/login' has been locally deleted
- You are now on branch 'develop'

git branch နဲ့ ကြည့်လိုက်ရင် develop branch ထဲရောက်နေတာကိုတွေ့ရမှာဖြစ်ပြီး login branch က file တွေ merge ဖြစ်နေတာကိုတွေ့ရမှာဖြစ်ပါတယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflow-demo$ git branch
* develop
  main
thaunghtikeoo@thaunghtikeoo:~/gitflow-demo$ ls
demo  index.html

အခု develop နဲ့ main branch ထဲက file တွေကို github ထဲကို push လိုက်ပါမယ်။

git checkout main
ls
git add .
git commit -am 'main'
git branch -M main
git remote add origin https://github.com/thaunggyee/gitflowdemo.git
git push -u origin main

git checkout develop
git add .
git commit -am 'develop'
git branch -M develop
git remote add origin https://github.com/thaunggyee/gitflowdemo.git
git push --set-upstream origin develop

နောက်ထပ် feature branch တွေအတွက်လည်းအခုလိုပဲ create နိုင်ပါတယ်။ feature branch ကို finish လိုက်တာနဲ့ main နဲ့ develop ကို code တွေက merge ဖြစ်မှာဖြစ်ပါတယ်။

👉 Release Branch

release branch ကလည်းအကုန်သိပြီးတဲ့အတိုင်း release တစ်ခုလုပ်ဖို့အတွက် release branch တစ်ခု create ပေးတာပါ။ git flow မှာလည်း release branch ကို finish လုပ်လိုက်ရင် code တွေနဲ့ tags တွေက main နဲ့ develop branch ကို merge ဖြစ်သွားမှာဖြစ်ပါတယ်။ ဒါဆို release branch တစ်ခု create လိုက်ပါမယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ git flow release start 0.1.0
Switched to a new branch 'release/0.1.0'

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

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

     git flow release finish '0.1.0'

release branch ထဲမှာ release.txt ကိုထည့်လိုက်ပါမယ်။

touch release.txt

ပြီးသွားရင်တော့ release branch ကို finish လုပ်လိုက်ပါမယ်။ code တွေက main branch နဲ့ develop ကို local merge ဖြစ်သွားမှာပါ။ release branch ဆိုတော့ tag တစ်ခုပါထွက်လာပါမယ်။ github ထဲကို ရောက်ဖို့ဆိုရင်တော့ git push လုပ်ပေးရမှာဖြစ်ပါတယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ git flow release finish 0.1.0
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Merge made by the 'recursive' strategy.
 demo       | 0
 index.html | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 demo
 create mode 100644 index.html
Deleted branch release/0.1.0 (was 86214ed).

Summary of actions:
- Release branch 'release/0.1.0' has been merged into 'main'
- The release was tagged '0.1.0'
- Release tag '0.1.0' has been back-merged into 'develop'
- Release branch 'release/0.1.0' has been locally deleted
- You are now on branch 'develop'

git branch နဲ့ ကြည့်လိုက်ရင် develop branch ထဲကို ရောက်နေတာကိုတွေ့ရမှာပါ။ ls နဲ့ကြည့်လိုက်ရင် release branch ထဲက release.txt merge ဖြစ်နေတာကိုတွေ့ရမှာဖြစ်ပြီး git tag နဲ့ကြည့်လိုက်ရင် tag တစ်ခုတွေ့ရမှာဖြစ်တယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ ls
demo  index.html  release.txt
thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ git tag
0.1.0

github repo ထဲကို ရောက်ဖို့ဆိုရင်တော့ push လုပ်ပေးဖို့လိုပါတယ်။ tag ကိုပါ push လုပ်ပေးရပါမယ်။

git checkout main
ls
git add .
git commit -am 'main'
git branch -M main
git remote add origin https://github.com/thaunggyee/gitflowdemo.git
git push -u origin main
git push --tags

git checkout develop
git add .
git commit -am 'develop'
git branch -M develop
git remote add origin https://github.com/thaunggyee/gitflowdemo.git
git push --set-upstream origin develop
git push --tags

👉 Hotfix Branch

production မှာ bug တစ်ခုခုဖြစ်တာမျိုး security flaw တစ်ခုခုဖြစ်တာမျိုးဆို hotfix branch ကနေ merge လုပ်ပေးမှာပါ။ hotfix branch ဆိုတာက အပေါ်က feature ၊ release တို့လိုပဲ finish တဲ့အခါ main branch နဲ့ develop branch ကို merge လုပ်ပေးမှာပါ။ release လို tag တစ်ခုကို ထုတ်ပေးမှာပါ။ hotfix branch တစ်ခု create ပါမယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ git flow hotfix start hb
Switched to a new branch 'hotfix/hb'

Summary of actions:
- A new branch 'hotfix/hb' was created, based on 'main'
- You are now on branch 'hotfix/hb'

Follow-up actions:
- Start committing your hot fixes
- Bump the version number now!
- When done, run:

     git flow hotfix finish 'hb'

hotfix.txt ဆိုတဲ့ file တစ်ခု create ပြီး finish လုပ်လိုက်ပါမယ်။

thaunghtikeoo@thaunghtikeoo:~/gitflowdemo$ git flow hotfix finish hb
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Merge made by the 'recursive' strategy.
 release.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 release.txt
Deleted branch hotfix/hb (was caf7fe2).

Summary of actions:
- Hotfix branch 'hotfix/hb' has been merged into 'main'
- The hotfix was tagged 'hb'
- Hotfix tag 'hb' has been back-merged into 'develop'
- Hotfix branch 'hotfix/hb' has been locally deleted
- You are now on branch 'develop'

git branch နဲ့ ကြည့်လိုက်ရင် develop branch ထဲရောက်နေတာကိုတွေ့ရမှာဖြစ်တယ်။ git tag နဲ့ tags တွေကိုကြည့်ရင်လည်း hb ဆိုပြီး tag တစ်ခုကိုတွေ့ရမှာဖြစ်ပါတယ်။ github ထဲ push ချင်ရင်တော့ git push နဲ့ push လုပ်ပေးလိုက်ပါ။ တစ်ခြား branch တွေဖြစ်တဲ့ bugfix branches မျိုးတွေလည်း git flow ကနေ လုပ်လို့ရပါသေးတယ်။

👉 Conclusion

ကျွန်တော်သိသလောက် git flow အကြောင်းကို ရှင်းပြခဲ့တာပါ။ အမှားအယွင်းတွေများပါခဲ့ရင်လည်း နားလည်ပေးဖို့တောင်းဆိုပါရစေ။ အားလုံးကိုကျေးဇူးတင်ပါတယ်။

သင်ဆရာ မြင်ဆရာ ကြားဆရာများကိုလေးစားလျှက် 🙏🙏🙏

သောင်းထိုက်ဦး (UIT)



Recent Posts