🛠️ ขั้นตอนทั้งหมด
✅ 1. เตรียมโฟลเดอร์โปรเจกต์ในเครื่อง
เช่น มีโปรเจกต์อยู่ใน C:\Users\you\myproject
หรือที่ไหนก็ได้
cd path/to/your/project
ถ้ายังไม่มี Git ในโปรเจกต์นั้น ให้เริ่มต้น Git:
git init
🧑💻 2. สร้าง Repository บน GitHub
-
ไปที่หน้าเว็บ: https://github.com/new
-
กรอกข้อมูล:
-
Repository name: ตั้งชื่อ เช่น
myproject
-
เลือก: ✅ Public หรือ 🔒 Private
-
ไม่ต้องติ๊ก README (เพราะเรามีไฟล์ local อยู่แล้ว)
-
-
กดปุ่ม
Create repository
หลังจากสร้างเสร็จ GitHub จะบอก URL ให้ เช่น:
https://github.com/yourname/myproject.git
🔗 3. เชื่อมโปรเจกต์ local กับ GitHub
กลับมาที่ Terminal พิมพ์:
git remote add origin https://github.com/yourname/myproject.git
📤 4. Add, Commit และ Push โค้ดขึ้น GitHub
git add .
git commit -m "Initial commit"
git push -u origin main
🔁 ถ้า push แล้วเจอ error ว่า
main
ไม่มี หรือ branch เป็นmaster
:
ให้ลองเช็กว่า local ใช้ branch อะไร:
git branch
ถ้าเป็น master
ให้เปลี่ยนคำสั่งเป็น:
git push -u origin master
🔐 ถ้าเจอให้ใส่ username/password
GitHub ปัจจุบันต้องใช้ Personal Access Token (PAT) แทน password:
-
กด
Generate new token
-
เลือก scopes อย่างน้อย:
repo
-
สร้างแล้ว Copy token ไปใส่ในช่อง Password เวลา push