DEV Community

Ans for Woxa Coperation

Posted on • Edited on

Setup git สำหรับทำงานกันเถอะ

สำหรับ Version control ที่ Woxa จะใช้ Gitlab กันเป็นหลัก ดังนั้นในบล็อคนี้จะใช้ Gitlab ครับ แต่วิธีการ Setup ก็เหมือนๆกัน

1 ไปที่ ssh โดยใช้คำสั่ง

cd ~/.ssh
Enter fullscreen mode Exit fullscreen mode

และ Gen ssh key กันก่อน ด้วยคำสั่ง

ssh-keygen -t rsa -b 2048 -C "your_email"
Enter fullscreen mode Exit fullscreen mode

แล้วมันจะถามเราว่า
Enter file in which to save the key (/Users/ans/.ssh/id_rsa):

เราจะใส่หรือไม่ใส่ก็ได้ ถ้าไม่ใส่ก็กด Enter ไปเลย แต่ในที่นี้ผมจะใส่เป็น id_rsa_gitlab จะได้แยกถูกว่า key ไหนใช้กับอะไร

ssh-keygen

และถัดมาจะมีช่องให้กรอก passphrase เผื่อ Key หลุดไป ถ้าไม่มี password ก็จะใช้ไม่ได้ แนะนำให้กรอกครับ แต่ถ้าไม่กรอกก็แค่ Enter ยาวๆไปครับ

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

2 เพิ่ม key เข้าไปใน ssh-agent เพื่อช่วยจำ passphrase ของ ssh key ถ้าเราไม่ได้ตั้ง passphrase ก็ข้ามข้อ 2 ไปเลยก็ได้ครับ

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

รันคำสั่ง ssh-add แล้วกรอก passphrase ของ key นั้นๆ

ssh-add ~/.ssh/id_rsa_gitlab
Enter fullscreen mode Exit fullscreen mode

และเราสามารถดู list key ที่เราสร้างขึ้นมาได้จากคำสั่ง

ssh-add -l
Enter fullscreen mode Exit fullscreen mode

3 เอา public key ไปใส่ใน gitlab

cat ~/.ssh/id_rsa_gitlab.pub
Enter fullscreen mode Exit fullscreen mode

จะได้หน้าตาแบบนี้

[Public key]

ให้ copy key ไปวางไว้ที่ gitlab

https://gitlab.com/-/profile/keys

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay