Git คืออะไร ? ว่าง่ายๆ Git ก็คือ opensource ที่ใช้เป็น version control system นั่นแหละครับ หรือ นิยามเต็มๆ ก็คือ
Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.Branching and merging are fast and easy to do. Git is used for version control of files, much like tools such as Mercurial, Bazaar, Subversion, CVS, Perforce, andVisual SourceSafe. อ้างจาก http://git-scm.com/
พอพูดถึงนิยามไปแล้ว เรามาลองใช้ git กันเลยดีกว่า
- เราต้องติดตั้ง git ก่อน (Download and install Git )
- ทดลองสร้าง Directory หรือไฟล์ ดังนี้ $ mkdir ProjectName $ cd ProjectName $ touch README
- สั่ง git init เพื่อสร้าง repository $ git init
- เมื่อสร้างไฟล์ใดๆแล้วให้สั่ง git add ชื่อไฟล์ หรือถ้าต้องการ add ทั้งหมดก็สั่ง git add . ได้เลย $ git add .
- เมื่อทำอะไรเรียบร้อยแล้วก็ต้องยืนยันการกระทำโดยสั่ง git commit -m ‘COMMENT’ $ git commit -m ‘First Commit README added)
- ถ้าต้องการสร้าง branch ใหม่ก็สั่ง git branch branchname $ git branch newbranch
- ต้องการ switch branch ก็สั่ง git check branchname $ git checkout newbranch $ git branch
ตามไปดู ตัวอย่างการใช้งานจริงได้ที่ VDO การพัฒนา Grails application ร่วมกับ Git เพื่อเพิ่ม productivity ก็ได้คร้าบบ
คราวหน้ามาพูดถึง github กันครับ
