Git Commands Cheat Sheet
Comprehensive Git command reference organized by workflow.
Setup & Config
git config --global user.name "Name"Set global usernamegit config --global user.email "email"Set global emailgit config --listList all config settingsgit initInitialize a new local repositorygit clone <url>Clone a remote repositoryStaging & Committing
git statusShow working tree statusgit add <file>Stage a specific filegit add .Stage all changesgit commit -m "message"Commit staged changes with a messagegit commit --amendModify the last commitgit diffShow unstaged changesgit diff --stagedShow staged changesBranching
git branchList all local branchesgit branch <name>Create a new branchgit checkout <branch>Switch to a branchgit checkout -b <branch>Create and switch to a new branchgit switch <branch>Switch to a branch (modern)git switch -c <branch>Create and switch to a new branch (modern)git branch -d <branch>Delete a merged branchgit branch -D <branch>Force-delete a branchgit merge <branch>Merge a branch into current branchgit rebase <branch>Rebase current branch onto anotherRemote Repositories
git remote -vList remote connectionsgit remote add origin <url>Add a remote named origingit fetchDownload remote changes without merginggit pullFetch and merge remote changesgit pull --rebaseFetch and rebase instead of mergegit push origin <branch>Push branch to remotegit push -u origin <branch>Push and set upstream trackinggit push --force-with-leaseSafe force push (checks remote)History & Log
git logShow commit historygit log --oneline --graphCompact branch graphgit log -n 10Show last 10 commitsgit log --author="name"Filter commits by authorgit blame <file>Show who changed each linegit show <commit>Show details of a specific commitUndoing Changes
git restore <file>Discard unstaged changes in a filegit restore --staged <file>Unstage a filegit reset HEAD~1Undo last commit, keep changes stagedgit reset --soft HEAD~1Undo last commit, keep changesgit reset --hard HEAD~1Undo last commit, discard changesgit revert <commit>Create a new commit that undoes a commitgit stashStash uncommitted changesgit stash popApply and remove latest stashgit stash listList all stashesTags
git tagList all tagsgit tag v1.0.0Create a lightweight taggit tag -a v1.0.0 -m "Release"Create an annotated taggit push origin --tagsPush all tags to remotegit tag -d v1.0.0Delete a local tagเกี่ยวกับเครื่องมือนี้
คู่มืออ้างอิงคำสั่ง Git ให้ดัชนีค้นหาคำสั่ง Git ที่จำเป็นใน 7 หมวดหมู่: การตั้งค่า, staging และ commit, branch, remote, ประวัติ, ยกเลิกการเปลี่ยนแปลง และ tag
ใช้ช่องค้นหาเพื่อกรองทันทีตามชื่อคำสั่งหรือคำอธิบาย บันทึกหน้านี้และกลับมาเมื่อต้องการทบทวน syntax อย่างรวดเร็ว
วิธีใช้งาน
- พิมพ์ชื่อคำสั่งหรือคำสำคัญในช่องค้นหา (เช่น commit, branch, remote)
- คำสั่งที่ตรงกันจะถูกกรองตามหมวดหมู่แบบเรียลไทม์
- ตรวจสอบคำสั่งและคำอธิบาย
- ล้างช่องค้นหาเพื่อแสดงรายการทั้งหมด
กรณีการใช้งาน
นักพัฒนาใช้เพื่อทบทวน syntax คำสั่ง Git อย่างรวดเร็วโดยไม่ต้องออกจากเบราว์เซอร์ ผู้เริ่มต้นได้ประโยชน์จากโครงสร้างตามหมวดหมู่ขณะเรียนรู้ Git มีประโยชน์ในระหว่าง code review เพื่อค้นหาการดำเนินการ git เฉพาะอย่างรวดเร็ว
คำถามที่พบบ่อย
- ทำไมคำอธิบายคำสั่งถึงเป็นภาษาอังกฤษ? — คำสั่งและ flag ของ Git เป็นมาตรฐานทางเทคนิคสากล การรักษาภาษาอังกฤษช่วยป้องกันการแปลผิดของคำศัพท์ทางเทคนิค
- รวมคำสั่ง Git ทั้งหมดหรือไม่? — ครอบคลุมคำสั่งที่ใช้บ่อยที่สุด สำหรับอ้างอิงครบถ้วน โปรดดูเอกสาร git อย่างเป็นทางการ