Git 101 – Commands and Workflows Cheat Sheet
A quick, task-oriented Git reference. Pair this with the in-depth guide for concepts and best practices.
Minimal Mental Model
graph LR
WD[Working Dir] -- add --> ST[Staging]
ST -- commit --> REPO[Local Repo]
REPO -- push --> ORI[Origin]
ORI -- fetch/pull --> REPO
Setup
git --version
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
Create or Clone
Status and Diffs
Stage and Commit
git add <path>
git add -p # interactive hunks
git commit -m "feat: message"
git commit --amend # edit last commit
Branching
Sync with Remote
Merge vs Rebase
Resolve Conflicts
git status
# edit files, remove markers
git add <file>
git commit # after merge
git rebase --continue # during rebase
Stash Work
Undo Safely
git restore --staged <file> # unstage
git restore <file> # discard local edits
git revert <sha> # new commit to undo
git reset --soft HEAD~1 # keep changes, drop last commit
git reflog # find lost commits
Tags and Releases
Ignore and Clean
Authentication (Quick)
# HTTPS + PAT
git clone https://github.com/owner/repo.git
# SSH
ssh-keygen -t ed25519 -C "[email protected]"
ssh-add ~/.ssh/id_ed25519
git clone [email protected]:owner/repo.git
Conventional Commits (Optional)
feat(auth): add oauth login
fix(api): handle null pointer in user service
chore(ci): update node to 20
Common One-Liners
# See last commit summary
git log -1 --stat
# Interactive rebase last 5 commits
git rebase -i HEAD~5
# Squash branch onto main
git switch my-branch && git rebase -i main
Quick PR Flow (GitHub)
See also: the full guide “The Definitive Guide to Version Control with Git and GitHub”.
Share this post: