วันจันทร์ที่ 9 กันยายน พ.ศ. 2556

วิธีการ Push File To Bitbucket อย่างง่าย (Command Line)

สิ่งที่ต้องการ

  • account ของ bitbucket ถ้ายังไม่มี คลิก
  • ติดตั้ง Git ถ้ายังไม่ได้ติดตั้ง คลิก

มาเริ่มกันเลย...

1. เปิด Git Bash ขึ้นมา Start > All Programs > Git > Git Bash


2. ใช้คำสั่ง command line ไปยัง directory ของไฟล์ที่เราต้องการ cd /path/your/project 


3. ตรวจสอบรายการไฟล์ที่เราจะเอาขึ้นว่ามีจริงหรือเปล่า ด้วยคำสั่ง ls


4. กำหนดค่าเริ่มต้น Repository ด้วยคำสั่ง git init


5. กำหนด URL Repository ของ Bitbucket ด้วยคำสั่ง git remote add origin https://username@bitbucket.org/username/repositoryName.git
เช่น git remote add origin https://cyberpunk_ken@bitbucket.org/cyberpunk_ken/simpletest.git
(ถ้ายังไม่ได้สร้าง Repository คลิก)


7. ตรวจสอบไฟล์ทั้งหมดว่ามีอยู่ใน Local System หรือเปล่า คำสั่ง git status 



6. ผมต้องการเอา project ที่ชื่อว่า SimplePush ไปไว้ที่ Repository ที่สร้างไว้ที่ Bitbucket 
    ใช้คำสั่ง  git add SimplePush/


7. ตรวจสอบอีกครั้งด้วยคำสั่ง get status


พบว่า project ที่ชื่อ SimplePush หายไปจาก Local System แล้ว
  • รายการสีเขียว คือ ไฟล์ที่ถูกย้าย
  • รายการสีแดง คือ Project ที่เหลืออยู่ใน Local System

8. ถึงแม้ว่า Project จะหายไปจาก Local Repository แล้ว แต่ก็ยังไม่ได้ถูกย้ายนะครับ เราต้องทำการ          commit ซะก่อน ด้วยคำสั่ง git commit -m "[message]"
 เช่น git commit -m "commit SimplePush"
  • message คือ คำอธิบายเพิ่มเติมสำหรับ commit 


9. ต่อไปเป็นขั้นตอนสุดท้ายครับ เป็นการ push file to bitbucket จริงๆ ล่ะ ^๐^ 
ลุยเลยครับ พิมพ์คำสั่ง git push -u origin master 
ระบบจะให้กรอก password ครับ เป็น password ตัวเดียวกันกับที่ใช้ Login Bitbucket ครับ



10. สำเร็จแล้วครับ สำหรับการ Push File To Bitbucket ลอง Login Bitbucket ครับ แล้วเลือกเมนู Source จะพบว่า Project ได้ถูกย้ายมาที่ Repository เรียบร้อยแล้ว ^^










2 ความคิดเห็น:

  1. มันขึ้นแบบนี้เกิดจากอะไรคะ?
    $ git push -u origin master
    To https://bitbucket.org/59160877/web-base.git
    ! [rejected] master -> master (fetch first)
    error: failed to push some refs to 'https://59160877@bitbucket.org/59160877/web-base.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    ตอบลบ
    คำตอบ
    1. ลองใช้คำสั่งนี้ดูนะครับ git push origin master --force

      ลบ