DEV Community

Tossapol Ritcharoenwattu
Tossapol Ritcharoenwattu

Posted on

Workshop CI/CD : Step 3 Push bank-api ไปยัง Gitlab

ในโฟลเดอร์ bankapi_go รันคำสั่ง Git:

git init
git remote add origin http://localhost:8080/rocky/bank-api-project.git
git add .
git commit -m "Initial commit of Go bank API"
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

ระบบจะถาม Username/Password ให้ใส่ rocky และรหัสผ่าน GitLab ที่คุณตั้งไว้

สามารถ push code ไปยัง gitlab สำเร็จ

============================================================

** ปัญหาที่พบ

ปัญหา : git commit

ปัญหานี้เกิดจาก Git ยังไม่รู้จักว่าคุณเป็นใคร ทุกครั้งที่ทำการ commit, Git จะต้องบันทึกว่าใครเป็นคนทำ
วิธีแก้ไข
ให้คุณตั้งค่าชื่อและอีเมลของคุณใน Git โดยใช้คำสั่งที่ระบบแนะนำมาได้เลยครับ
ตั้งค่าชื่อผู้ใช้:

git config --global user.name "ชื่อของคุณ"
Enter fullscreen mode Exit fullscreen mode

(ให้เปลี่ยน ชื่อของคุณ เป็นชื่อจริงของคุณ)

ตั้งค่าอีเมล:

git config --global user.email "อีเมลของคุณ"
Enter fullscreen mode Exit fullscreen mode

(ให้เปลี่ยน อีเมลของคุณ เป็นอีเมลที่คุณใช้กับ GitLab)

ปัญหา : git push branch ไม่ตรงกัน

ต้องทำการเปลี่ยน branch master เป็น main ก่อน ด้วย command

git branch
git branch -M main
Enter fullscreen mode Exit fullscreen mode

ปัญหา : git push ไม่ได้เพราะมีไฟล์ถูกแก้ไขใน gitlab ทำให้ข้อมูลไม่ตรงกับใน project ของเรา แก้ปัญหาโดย สั่ง merge gitlab กับ project ในเครื่องก่อน จะ push

git pull --rebase origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)