Home | Back
Git โปรแกรมสำหรับทำ control version แบบ distributed อันทรงพลัง
Wednesday, 27 February 2013
ในการพัฒนาซอฟท์แวร์ในลักษณะที่เป็นทีมเวิร์คหรือพัฒนาเดี่ยวก็ตาม ควรจะต้องมีระบบสำหรับเก็บตัว sourcecode ที่เราได้พัฒนาขึ้น ซึ่งสามารถที่จะปรับปรุง sourcecode ในลักษณะเป็น revision ได้ รวมทั้งมีคุณสมบัติในการรวม sourcecode จากนักพัฒนาหลาย ๆ คนมาเป็น sourcecode หนึ่งเดียวกันได้ ซึ่งระบบที่ตอบโจทย์เหล่านี้ได้คือระบบ control version นั่นเอง โดยระบบ control version ที่นิยมกันก็จะมี cvs, svn, mercurial, bazaar รวมทั้ง git ซึ่งเป็นระบบที่ผมจะกล่าวถึงในบทความนี้ครับ
repository ภายนอกสำหรับ git ที่น่าสนใจก็มีหลายตัวครับ ที่ผมจะแนะนำคือ bitbucket, github, gitlab, gitorious และ sourceforge ครับ ทดลองกันดูได้นะครับ
1. เริ่มต้นใช้ git
สำหรับ ubuntu เราต้องลง git ก่อนครับ ดังนี้
$ sudo aptitude install git
จากนั้นให้กำหนดข้อมูลสำหรับผู้ใช้ git ดังนี้ครับ
$ git config --global user.name "Authapon Kongwan" $ git config --global user.email "authapon@gmail.com"
2. สร้าง local repository
สมมุติว่าผมได้สร้าง repository ภายนอกที่ bitbucket ชื่อ hello ไว้แล้วนะครับ ซึ่งเป็น repository ว่าง ๆ เท่านั้น จากนั้นผมจะทำการสร้าง sourcecode เป็นไฟล์ชื่อ hello.c ในเครื่องของตัวเองดังนี้นะครับ
$ mkdir hello $ cd hello $ vim hello.c
File : hello.c
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
return 0;
}
ตอนนี้เรามี sourcecode ตั้งต้นแล้ว จากนั้นเราก็ทำการสร้าง local repository และทำการเพิ่มไฟล์เข้าสู่ repository แล้วทำการ commit ไฟล์ จากนั้นก็กำหนด remote repository และสุดท้ายก็ทำการ push ไฟล์เข้าไปเก็บยัง remote repository ดังนี้
$ git init Initialized empty Git repository in /home/moo/repo/hello/.git/ $ git add . $ git commit -m 'first commit' [master (root-commit) daf2ae9] first commit 1 files changed, 7 insertions(+), 0 deletions(-) create mode 100644 hello.c $ git remote add origin https://authapon@bitbucket.org/authapon/hello.git $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello.git * [new branch] master -> master
ในการ push ไฟล์เข้าสู่ repository นั้น เราจะใช้คำสั่ง git push origin master โดย origin คือชื่อของ remote repository ที่เราตั้งเอาไว้ คือ https://authapon@bitbucket.org/authapon/hello.git ซึ่งเราได้สร้างไว้เป็น repoistory ว่าง ๆ ที่ bitbucket ส่วน master คือ branch หลักที่เราใช้เก็บ sourcecode นั่นเอง
3. การ clone repository, การตรวจสอบสถานะไฟล์, การเพิ่มไฟล์ และการลบไฟล์
เราจำลองเหตุการณ์ว่า เราได้ย้ายไปทำงานที่เครื่องอื่น การที่เราจะทำการไข sourcecode ของเราได้นั่น เราต้องทำการ clone ตัว sourcecode ของเรามาจาก repository ก่อน ดังนี้ครับ
$ git clone $ git clone https://authapon@bitbucket.org/authapon/hello Cloning into 'hello'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done.
จากคำสั่งข้างต้น จะเป็นการ clone ตัว sourcecode ของเรามายังโฟล์เดอร์ hello นั่นเอง ซึ่งเราก็จะทำการแก้ไขตัว sourcecode ของเรา โดยการเข้าไปยังโฟล์เดอร์ hello จากนั้นเราจึงแก้ไข sourcecode ของเราตังตัวอย่างนี้ครับ
$ cd hello/ $ ls hello.c $ vim hello.c
File : hello.c
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
printf("how are you, today!!!\n");
return 0;
}
โดยในส่วนที่เป็นสีส้มคือส่วนที่เราได้แก้ไขเพิ่มเติมเข้าไปครับ
ขณะนี้ได้มี sourcecode ของเราบางส่วนได้ถูกแก้ไข ซึ่งเราสามารถตรวจสอบได้ด้วยคำสั่ง git status ดังนี้ครับ
$ git status # On branch master # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: hello.c # no changes added to commit (use "git add" and/or "git commit -a")
จะเห็นว่ามีการแสดงข้อความว่ามีไฟล์ hello.c ได้ถูก modified หรือถูกแก้ไขเปลี่ยนแปลงนั่นเอง ซึ่งสถานะต่าง ๆ ของไฟล์ sourcecode นั่นจะมีได้หลายรูปแบบ เช่น ไฟล์ใหม่ที่ยังไม่ได้ดึงเข้ามายัง local repository หรือไฟล์ไหนที่ถูกลบออกไปจาก local repository โดยเราจะจำลองเหตุการณ์ว่า เราได้มีการสร้างไฟล์ใหม่เข้ามายัง local repository โดยเราจะสร้างไฟล์ที่ชื่อ adding.c เข้ามายัง local repository ของเราดังนี้ครับ
$ vim adding.c
File : adding.c
#include <stdio.h>
int adding(int a,int b)
{
return a+b;
}
เมื่อเราตรวจสอบสถานะของไฟล์เราจะได้ดังนี้ครับ
$ git status # On branch master # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: hello.c # # Untracked files: # (use "git add ..." to include in what will be committed) # # adding.c no changes added to commit (use "git add" and/or "git commit -a")
จะเห็นว่าไฟล์ adding.c จะถูกแสดงว่าเป็น Untracked files ซึ่งหมายถึงไฟล์นี้ไม่ได้ถูกผนวกเข้าสู่ระบบ local repository ของเรานั่นเอง ขั้นตอนต่อมาเราจึงต้องทำการนำไฟล์ใหม่นี้เข้าสู่ระบบ และเมื่อเสร็จแล้วจึงทำการ commit และ push ไฟล์ต่อไปดังนี้ครับ
$ git add . $ git commit -m 'second commit' [master 275c9c3] second commit 2 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 adding.c $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello ce5cc97..23d1985 master -> master
ในการลบไฟล์ออกจาก local repository ของเรา ทำได้โดยคำสั่ง git rm ดังนี้ครับ
$ git rm adding.c rm 'adding.c' $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # deleted: adding.c #
จะเห็นว่าได้มีการแสดงสถานะ deleted ว่ามีไฟล์ adding.c ได้ถูกลบออกจาก local repository
จากนั้นเราจึงทำการ commit ความเปลี่ยนแปลงนี้และ push เข้าสู่ repository ภายนอกของเราดังนี้ครับ
$ git commit -m 'deleted some file' [master 27365c3] deleted some file 1 files changed, 0 insertions(+), 7 deletions(-) delete mode 100644 adding.c $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello 23d1985..2f12cd3 master -> master
4. การ pull
ในกรณีที่เราทำการแก้ไข sourcecode จากคอมพิวเตอร์หลาย ๆ เครื่อง หรืออาจจะมีการพัฒนาระบบกันหลาย ๆ คน เราจะเกิดปัญหาเรื่องของการที่ sourcecode ของในที่ละที่ หรือในของแต่ละคนนั้น ไม่ update หรือไม่รู้ว่าอันไหน update กว่ากัน ซึ่งเราสามารถแก้ไขปัญหาได้ด้วยการ pull โดยเราสมมุติว่าได้มีการแก้ไข sourcecode จากเครื่องส่วนตัว โดยการ clone มาไว้ในโฟล์เดอร์ hello ดังนี้
$ git clone https://authapon@bitbucket.org/authapon/hello hello Cloning into 'hello'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 9, done. remote: Compressing objects: 100% (7/7), done. remote: Total 9 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (9/9), done.
จากนั้นสมมุติว่าผมแก้ไขเสร็จก็ commit และ push ไปเก็บยัง repository แล้ว ผมเกิดไปที่ทำงานและทำการแก้ไข sourcecode จากเครื่องที่ทำงาน ผมก็สามารถ clone มายังเครื่องที่ทำงานได้ ซึ่งผมสมมุติว่า clone ไปยังโฟล์เดอร์ hello2 และทำการแก้ไข sourcecode ดังนี้ครับ
$ git clone https://authapon@bitbucket.org/authapon/hello hello2 Cloning into 'hello2'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 9, done. remote: Compressing objects: 100% (7/7), done. remote: Total 9 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (9/9), done. $ cd hello2 $ vim hello.c
File : hello.c
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
printf("how are you, today!!!\n");
printf("I'm fine, thanks...\n");
return 0;
}
เราได้แก้ไขไฟล์ hello.c เพิ่มเติมในส่วนที่เป็นสีส้ม จากนั้นเราก็ทำการ commit และ push ดังนี้
$ git add . $ git commit -m 'add some line' [master 53fc134] add some line 1 file changed, 1 insertion(+) $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello 2f12cd3..53fc134 master -> master
จากนั้นผมก็กลับมาที่บ้าน และต้องการแก้ไข sourcecode จากเครื่องคอมพิวเตอร์ส่วนตัว ซึ่งผมเคย clone ไว้แล้วที่โฟล์เดอร์ hello แต่ sourcecode ตัวนี้ไม่ใช่ตัวล่าสุดแล้ว ผมสามารถทำการ pull ความเปลี่ยนแปลงของ sourcecode ได้และทำการ update ความเปลี่ยนแปลงของ sourcecode ได้ดังนี้
$ git pull
WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory
Password for 'https://authapon@bitbucket.org':
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://bitbucket.org/authapon/hello
2f12cd3..53fc134 master -> origin/master
Updating 2f12cd3..53fc134
Fast-forward
hello.c | 1 +
1 file changed, 1 insertion(+)
เราได้ใช้คำสั่ง git pull เพื่อดึงความเปลี่ยนแปลงที่เกิดขึ้นมายัง repository ของเรา โดยในส่วนที่เป็นสีส้ม จะเป็นข้อความที่แจ้งความเปลี่ยนแปลงใน sourcecode ของเรา จากนั้นก็ทำการแก้ไข sourcecode และ commit และ push ต่อไปดังนี้
$ vim hello.c
File : hello.c
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
printf("how are you, today!!!\n");
printf("I'm fine, thanks...\n");
printf("I'm still coding.\n");
return 0;
}
$ git add . $ git commit -m 'change some code' [master ae3c05c] change some code 1 file changed, 1 insertion(+) $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello 53fc134..ae3c05c master -> master
5. การ merge
ในการพัฒนาซอฟท์แวร์เป็นทีมนั้น จะมีโปรแกรมเมอร์หลายคนกำลังทำงานกับ sourcecode เดียวกัน เพียงแต่อาจจะแก้ไข sourcecode กันคนละ module ซึ่งเมื่อมีการ push ไปยัง repository นั้นบางครั้งอาจจะต้องมีการ merge เกิดขึ้น เนื่องจาก sourcecode ที่ตนเอง clone มานั้น ไม่ได้เป็น sourcecode รุ่นล่าสุดแล้ว ระหว่างที่เราทำการแก้ไข sourcecode เรานั้น อาจจะมีโปรแกรมเมอร์คนอื่นได้ push ก่อนหน้าเราไปแล้ว ฉะนั้น เราจะต้องทำการ pull ความเปลี่ยนแปลงมาที่ local repository ก่อน แล้วจึงทำการ merge จากนั้นค่อย commit และ push ต่อไปได้
สมมุติเหตุการณ์ว่ามีโปรแกรมเมอร์ A ได้ clone repository มาและทำการเพิ่มไฟล์ adding.c เข้ามาดังนี้
$ git clone https://authapon@bitbucket.org/authapon/hello.git Cloning into 'hello'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 15, done. remote: Compressing objects: 100% (11/11), done. remote: Total 15 (delta 3), reused 0 (delta 0) Unpacking objects: 100% (15/15), done. $ cd hello $ vim adding.c
File : adding.c
#include <stdio.h>
int adding(int a, int b)
{
return a+b;
}
ขณะเดียวกันโปรแกรมเมอร์ B ได้ทำการ clone repository มาเช่นเดียวกันและทำการเพิ่มไฟล์ sub.c ดังนี้
$ git clone https://authapon@bitbucket.org/authapon/hello Cloning into 'hello'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 15, done. remote: Compressing objects: 100% (11/11), done. remote: Total 15 (delta 3), reused 0 (delta 0) Unpacking objects: 100% (15/15), done. $ cd hello $ vim sub.c
File : sub.c
#include <stdio.h>
int sub(int a, int b)
{
return a-b;
}
จากนั้นโปรแกรมเมอร์ A ได้ทำการ commit และ push ตัว sourcecode เข้าสู่ repository ตามปกติดังนี้
$ git add . $ git commit -m 'adding.c added' [master ef12bb0] adding.c added 1 file changed, 6 insertions(+) create mode 100644 adding.c $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello.git ae3c05c..ef12bb0 master -> master
หลังจากนั้น เมื่อโปรแกรมเมอร์ B จะทำการ commit และ push บ้างก็จะเกิดเหตุการณ์ดังนี้ครับ
$ git add . $ git commit -m 'sub.c added' [master e49fd24] sub.c added 1 file changed, 6 insertions(+) create mode 100644 sub.c $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': To https://authapon@bitbucket.org/authapon/hello ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://authapon@bitbucket.org/authapon/hello' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
โปรแกรมเมอร์ B จะไม่สามารถ push ได้ เนื่องจาก sourcecode ใน repository นั้น ใหม่กว่า clone ของโปรแกรมเมอร์ A ดังนั้นโปรแกรมเมอร์ B จะต้องทำการ pull ความเปลี่ยนแปลงมาก่อน หากไม่มีความขัดแย้ง git จะทำการ merge ให้ทั้นที จากนั้นเราจึงทำการ push อีกครั้งดังนี้
$ git pull WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 4, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From https://bitbucket.org/authapon/hello ae3c05c..ef12bb0 master -> origin/master Merge made by the 'recursive' strategy. adding.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 adding.c $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello ef12bb0..fe9be2a master -> master
6. การ tag
ในการพัฒนาซอฟท์แวร์นั้นเมื่อทำไปจนถึงจุดนึงแล้ว อาจจะมีการตัดสินหมายเลขรุ่นหรือ version ขึ้น เราสามารถที่จะ tag จุดนั้นเอาไว้ว่าเป็น sourcecode รุ่นอะไร เผื่อว่าเมื่อเราพัฒนาไปเรื่อย ๆ แล้ว เราอาจจะอยากดู sourcecode รุ่นเก่า ๆ มาดูเพื่อเปรียบเทียบจุดประสงค์อื่นใดก็ได้ โดยการ tag ทำได้ดังนี้
$ git tag v1.0 -m 'version 1.0' $ git push origin v1.0 WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello * [new tag] v1.0 -> v1.0
จะเห็นว่าเราใช้คำสั่ง git tag แล้วตามด้วยข้อความที่เราต้องการ เพื่อทำการ tag จุดนี้ไว้ หลังจากนั้นจึงทำการ push tag ต่อไป
เราสามารถที่จะทำการ checkout ไปยัง tag ใดก็ได้ ด้วยคำสั่งดังนี้ครับ
$ git checkout v1.0 Note: checking out 'v1.0'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at fe9be2a... Merge branch 'master' of https://bitbucket.org/authapon/hello
และเราสามารถลบ tag ได้ดังคำสั่งต่อไปนี้
$ git tag -d v1.0 Deleted tag 'v1.0' (was 7dcfc75) $ git push origin :refs/tags/v1.0 WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello - [deleted] v1.0
7. การ branch
เมื่อมีการพัฒนาซอฟท์แวร์ไปถึงจุดนึง อาจจะเกิดความต้องการเปลี่ยนแปลงโครงสร้างหรือแนวคิดบางอย่างขึ้น โดยบางครั้งเป็นเพียงการทดสอบแนวคิด จึงอาจจะมีการต้องการแยกพัฒนาซอฟท์แวร์แยกไปอีกทางนึงซึ่งมี sourcecode ไปในแนวทางอื่น แต่ต้องการเก็บตัว sourcecode ใหม่นี้ร่วมกับ sourcecode เดิม เช่น เราอาจจะพัฒนาโปรแกรมประมวลผลกีฬาซึ่งทำงานบนวินโดว์ แต่เราต้องการทำรุ่นสำหรับทำงานบนมือถือด้วย หรือทำงานบนลีนุกซ์ด้วย เป็นต้น โดยจะมี sourcecode ส่วนหนึ่งที่แตกต่างออกไปจากต้นฉบับ เราจะเรียกกรณีนี้ว่าการ branch นั่นเอง
โดยการ branch นั้น sourcecode ทั้งสองชุด จะอยู่ใน repository เดียวกันได้ โดย sourcecode ต้นฉบับจะถือว่าอยู่ใน branch master ส่วน sourcecode ที่แยกไป จะสามารถตั้งชื่อ branch ได้ตามต้องการ
สมมุติเหตุการณ์ว่าเราจะสร้าง branch ใหม่สำหรับ mobile version เราจะเริ่มด้วยการ clone repository เดิมมาก่อน จากนั้นจึงกำหนด branch ขึ้น แล้วทำการการ push branch กลับไปยัง repository นั่นเอง
$ git clone https://authapon@bitbucket.org/authapon/hello Cloning into 'hello'... WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: Counting objects: 23, done. remote: Compressing objects: 100% (19/19), done. remote: Total 23 (delta 5), reused 0 (delta 0) Unpacking objects: 100% (23/23), done. $ cd hello/ $ git branch * master $ git branch mobile $ git push origin mobile WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello * [new branch] mobile -> mobile
เราสามารถ checkout ไปยัง branch ใด ๆ ได้ดังนี้ครับ
$ git checkout mobile Switched to branch 'mobile'
เราสามารถเปลี่ยนชื่อ branch ได้ดังนี้ครับ
$ git branch -m mobile mobile2
ในกรณีนี้เราจะเปลี่ยนชื่อ branch ได้เฉพาะในเครื่องเราเท่านั้นครับ กรณีต่อไปเป็นการลบ branch เราสามารถทำได้ดังนี้ครับ
$ git branch -d mobile Deleted branch mobile (was fe9be2a).
หากต้องการลบ branch ที่เป็น remote เราทำได้ดังนี้ครับ
$ git push origin :mobile WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello - [deleted] mobile
สุดท้ายการ merge branch เข้าด้วยกัน สามารถทำได้ดังนี้ครับ
$ git checkout master Switched to branch 'master' $ git branch * master mobile $ git merge mobile Updating fe9be2a..c5abbcf Fast-forward a.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 a.c $ git commit -m 'merge master with mobile' # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) $ git push origin master WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-60c7NE/pkcs11: No such file or directory Password for 'https://authapon@bitbucket.org': remote: bb/acl: authapon is allowed. accepted payload. To https://authapon@bitbucket.org/authapon/hello fe9be2a..c5abbcf master -> master
เอาล่ะครับ ก็พอสังเขปนะครับ ขอเพิ่มอีกนิดนะครับ ในการเก็บไฟล์ sourcecode บางครั้งก็มีไฟล์ที่เกิดจากการแก้ไขไฟล์ เช่น .bak เป็นต้น เราต้องการให้ Git ทำการไม่สนใจไฟล์เหล่านี้ เราสามารถทำได้โดย สร้างไฟล์ .gitignore แล้วใส่ pattern ของรูปแบบไฟล์ที่ไม่ต้องการได้ เช่น
File : .gitignore
# Ignore all bin directories bin # Ignore all files ending with ~ *~ # Ignore the target directory # Matches "target" in any subfolder target/
สำหรับลิ้งค์ที่อธิบายเกี่ยวกับการใช้ Git ที่ดีใช้ได้ ผมแนะนำให้อ่านเพิ่มเติมได้ที่ Git Tutorial นะครับ หวังว่าคงเป็นประโยชน์บ้างนะครับ :)