อยากแก้ไข source code ของเราในเครื่องเราที่อยู่ใน Github.com เริ่มจาก pull แล้วค่อย push

ทบทวนกันนิดนึง  .. ก่อนไป clone vscode ของ microsoft
ปัจจุบันมีบัญชีใน Github.com แล้วอยากแก้ไข code ทั้งของเรา และของเขา บนเครื่องคอมพิวเตอร์ของเรา ถ้าเป็นของเราก็ push กลับไปได้ เริ่มจาก pull มาในเครื่องเรา พอแก้ไข code เสร็จ ก็ push กลับเข้าไป

clone vscode
clone vscode

มีขั้นตอนดังนี้

1. ติดตั้ง git หา Download
ได้ที่ https://git-scm.com/download

2. เข้า cmd หรือไม่ก็ใช้ Atom editor เป็นอีกทางเลือกนึง
สร้างห้องเตรียมรับ repository ที่จะดึงมาแก้ไข
อาทิ d:\git\mygitfriends
แล้ว cd d:\git\mygitfriends

3. พบห้อง DOS> หลัง run cmd
เคยเล่าขั้นตอน 9 ข้อใน http://www.thaiall.com/blog/burin/8875/
หรืออ่านเพิ่มเติมที่ https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
วันนี้สั้นหน่อย แบบรวบรัด
DOS> git init
DOS> git config –global user.email “test@test.com”
DOS> git config –global user.name “test”
DOS> git remote -v เพื่อดูว่าเชื่อมต่อทิ้งไว้แล้วหรือไม่ จะได้ไม่ซ้ำ เช่น burin
DOS> git remote remove burin แค่นี้ก็ล้างข้อมูลที่เคยเชื่อมต่อไว้ แต่ folder ไม่หายนะครับ
DOS> git remote add mytest https://github.com/thaiall/mygitfriends.git
DOS> git pull mytest master ก็ดึง branch:master ตามลิงค์ข้างต้นมาในเครื่อง ต่อไปก็เรียก mytest
ข้อมูลมาเยอะเลย ไม่ถาม user & password เพราะเป็น public และมีรูปนึกศึกษาเพียบเลย
DOS> notepad README.md
แล้วเพิ่ม This is my test on 16 september 2017. ต่อท้ายไปอีก 1 บรรทัด
เอาละ Mission complete แล้วนะ ต่อจากนี้ก็ push ล่ะ
DOS> git add README.md
เพื่อให้ git รู้ว่ามีรายการเปลี่ยนแปลง คือ “แฟ้มนี้นะ ที่ส่งเข้าประกวด”
DOS> git commit -m “i want to write lesson at http://www.thaiall.com/blog
DOS> git push -u mytest master
ผมเลิกใช้คำว่า origin จะได้ไม่สับสน เพราะเราใช้อะไรก็ได้ ไม่ต้อง origin
จากนี้ก็จะลบข้อมูลการทดสอบทิ้งหละครับ เพราะ Mission complete
เนื่องจาก login github.com ไว้แล้ว เมื่อ push ก็ไม่ถาม user & password อีก

4. ถ้าต้องการ project ใน github.com ไม่ต้อง pull ก็ได้
ใช้ clone เพื่อ download ลงมาเลย แบบนี้แก้แล้ว push กลับไม่ได้นะครับ
เริ่มต้นก็ลบทุกอย่างใน current directory ก่อน clone อะไรมาได้ ก็จะได้รู้

4.1 แบบ pull
เริ่มจากกำหนดชื่อ branch อาทิ mytest ในเครื่องเรา ที่จะเชื่อมกับ branch master
แบบนี้คล้ายกับ clone แต่หวังจะ push ถึงได้ใช้ pull
DOS> git init
DOS> git remote add mytest https://github.com/thaiall/mygitfriends.git
DOS> git pull mytest master
มาเลย

4.2 แบบ clone ไม่ต้องอะไร สั่ง git clone ตามด้วย url ก็มาเลย
ไม่ต้องสั่ง git init ก็ได้ download มาเลย แล้วสร้าง Folder แยกให้
DOS> git clone https://github.com/schacon/ticgit
DOS> git clone https://github.com/thaiall/mygitfriends
DOS> git clone https://github.com/toyoshim/SyobonAction
DOS> git clone https://github.com/Microsoft/vscode
ถ้ารอ download นาน แล้วอยากยกเลิก ก็กด Ctrl+C หรือ close window

Author: บุรินทร์ รุจจนพันธุ์

I am Lecturer, Developer, Researcher, Columnist, Writer, Photographer, and Webmaster - L@mpang man

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.