Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows

ติดตั้ง Git บน Windows: คู่มือขั้นตอนฉบับสมบูรณ์ สำหรับ Version Control

Git เป็น Version Control System มาตรฐานอุตสาหกรรม สำคัญสำหรับนักพัฒนาทุกคน บน Windows ต้องติดตั้งเอง บทความนี้แนะนำขั้นตอนติดตั้ง Git for Windows แบบละเอียด พร้อมตัวเลือกที่แนะนำ

ดาวน์โหลดและติดตั้ง Git for Windows

  1. ไปที่ git-scm.com/download/win
  2. ดาวน์โหลด Installer: 64-bit Git for Windows Setup (สำหรับ Windows 10/11 64-bit ทุกเครื่อง)
  3. รัน Installer (.exe)

ตัวเลือกติดตั้งที่แนะนำ (Recommended Options)

ติดตั้ง Git บน Windows: คู่มือขั้นตอนฉบับสมบูรณ์ สำหรับ Version Control

ผ่าน Wizard ตามลำดับ - ตัวเลือกที่ควรเลือก:

ขั้นตอนตัวเลือกที่แนะนำเหตุผล
Select ComponentsDefault (ติ๊ก Git Bash, Git GUI, Shell Integration)ครบถ้วนสำหรับใช้งานทั่วไป
Default EditorVisual Studio Code (หรือ Notepad++ / Vim)VS Code เป็นมาตรฐาน ปัจจุบัน Installer ตรวจจับ VS Code อัตโนมัติ
Initial Branch NameLet Git Decide (Default: main)ใช้ Branch name ใหม่มาตรฐาน (main แทน master)
PATH EnvironmentGit from the command line and also from 3rd-party softwareใช้ Git ได้จาก CMD, PowerShell, และ IDE ทุกตัว
SSH ExecutableUse bundled OpenSSHใช้ OpenSSH มาพร้อม Git ไม่ต้องพึ่ง Windows/OpenSSH แยกต่างหาก
HTTPS TransportUse the OpenSSL library (Default)มาตรฐาน รองรับ HTTPS ทุกกรณี
Line EndingsCheckout Windows-style, commit Unix-style (Default)จัดการ Line Endings (CRLF/LF) อัตโนมัติ ป้องกันปัญหา Cross-platform
Terminal EmulatorUse MinTTY (Default)Terminal สำหรับ Git Bash สวยงาม รองรับ Unicode ดี
Git Pull BehaviorDefault (Fast-forward or merge)พฤติกรรมมาตรฐาน
Credential HelperGit Credential Manager Core (Default - ไม่ใช่ None)จัดการ Credential (GitHub, Azure DevOps, Bitbucket) อัตโนมัติ และปลอดภัย
Extra Optionsติ๊ก: Enable file system caching, Enable symbolic linksเพิ่มประสิทธิภาพและรองรับ Symlinks

คลิก Install > รอเสร็จ > Finish

ยืนยันการติดตั้ง

ติดตั้ง Git บน Windows: คู่มือขั้นตอนฉบับสมบูรณ์ สำหรับ Version Control

  1. เปิด Git Bash (จาก Start Menu หรือติ๊ก Launch Git Bash ตอน Finish)
  2. พิมพ์: git --version
  3. ควรเห็น: git version 2.x.x.windows.y = ติดตั้งสำเร็จ!

การตั้งค่าเริ่มต้นหลังติดตั้ง (First-time Config)

# ตั้งค่าชื่อและอีเมล (ใช้สำหรับ Commits)
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# ตั้งค่า Default Branch (ถ้าไม่ได้เลือก Let Git Decide)
git config --global init.defaultBranch main

# ตรวจสอบการตั้งค่า
git config --global --list

ขั้นตอนต่อไป

  • GitHub Desktop / GitHub CLI (gh) - GUI/CLI สำหรับ GitHub
  • SSH Key Generation: ssh-keygen -t ed25519 -C "your.email@example.com" เพื่อ Clone/Push ผ่าน SSH
  • Git Aliases: สร้าง Shortcut คำสั่งยาว (เช่น git config --global alias.st status)

สรุป

ติดตั้ง Git บน Windows: ดาวน์โหลดจาก git-scm.com -> รัน Installer -> เลือกตัวเลือกแนะนำ (VS Code Editor, Let Git Decide, Git from CMD+3rd party, OpenSSH, GCM Core) -> Verify ด้วย git --version -> ตั้งค่า user.name/user.email เริ่มใช้งานได้เลย!