Download and Installation
Quick start (most-used)
git status
git add .
git commit -m "message"
git pull --rebase
git push
Config
Identity
git config --global user.name "Bendy Zhang"
git config --global user.email "[email protected]"
git config --global --list
Helpful defaults
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global fetch.prune true
git config --global rerere.enabled true
Ignore files globally
git config --global core.excludesfile ~/.gitignore_global
# edit ~/.gitignore_global
Workspace (working tree / index / HEAD)
- Working tree (workspace): Files you see and edit in your filesystem.
- Index / Staging area: What you get after
git add; ready to be committed.
- HEAD: The currently checked-out commit (usually the tip of the current branch).
Check workspace status
git status
git diff # workspace vs index
git diff --staged # index vs HEAD
Move changes between workspace and staging
git add <file>
git add -p
git restore --staged <file> # unstage
Discard workspace changes (dangerous)