How to use Git and Github Workflow
Essential git commands
- git add [filename] เพิ่ม file ที่แก้ไขแล้วอยากจะ push ขึ้น origin
>git add text.txt - git commit -m “comments” เขียน comment ว่าได้ทำอะไรไป
> git commit -m “add text files” - git push
> git push origin feature_branch - git log .
> git log -n 10 — pretty=oneline - pull request
> go to github.com to make pull request after push feature_branch to github
อันนี้เป็น structure ของ git workflow ที่เราใช้นะ
ของพี่คือ upstream https://github.com/kwarodom/sidtechtalent.git
ของน้องคือ origin https://github.com/dev-boom/sidtechtalent.git
ในเครื่องน้องคือ local (sidtechtalent)
กฏคือ
1. ต้องทำ upstream/master, origin/master, และ local/master ให้ commit เท่ากันตลอด
2. เวลา dev ห้ามทำใน local/master ต้องแตก branch เป็น local/feature_branch
3. ก่อน push ไปที่ origin ต้องทำ git pull upstream master มาที่ local/master และเอาไป rebase local/feature_branch
4. ต้องมั่นใจก่อน push ว่า local/feature_branch มีแค่ 1 commit มากกว่า upstream/master (เอา local/master มา rebase local/feature_branch ทำให้ local/master มี N commit และ local/feature_branch มี N+1 commit)
5. git push origin feature_branch
6. ไปที่ github แล้วทำ pull request จาก origin/feature_branch มาที่ upstream/master
7. code commit มันจะวนจาก local ไป origin ไป upstream วนลงมา local แล้ววนขวาไป ถ้างงกลับไปอ่านข้อ 1 ใหม่