A practical Git reference for everyday use, plus the stuff that saves your ass when you accidentally stage giant files, need to rewrite local history, or want to see what is really about to be pushed.
Basic config you usually set once.
git config --global user.name "Your Name" git config --global user.email "you@example.com"
git config --list
git init
The bread-and-butter commands.
git status -sb
git add .
git add path/to/file
git commit -m "your message"
git push -u origin "$(git branch --show-current)"
Create, switch, and inspect branches.
git branch -a
git switch -c my-branch
git switch main
git branch -d my-branch
Useful ways to see what happened and when.
git log --oneline --decorate --graph --all -20
git show COMMIT_HASH
git log -- path/to/file
git blame path/to/file
The stuff you use when you realize you messed something up.
git restore --staged path/to/file
git commit --amend --no-edit
git reset --soft HEAD~1
git reset HEAD~1
git reset --soft origin/main
Temporary parking spot for work in progress.
git stash push -m "WIP"
git stash list
git stash pop
Working with GitHub or any other remote.
git remote -v
git fetch origin
git pull
git remote set-url origin REPO_URL
Keep junk files out of the repo.
echo "*.mp4" >> .gitignore echo "*.flac" >> .gitignore
git rm --cached path/to/file
git check-ignore -v path/to/file
The exact sort of thing that saves you from GitHub rejecting a push.
git ls-files | grep -E '\.(mp4|flac)$'
branch=$(git branch --show-current) git rev-list --objects "origin/$branch..HEAD" | git cat-file --batch-check="%(objecttype) %(objectname) %(objectsize) %(rest)" | sort -k3 -n | tail -20
branch=$(git branch --show-current) git rev-list --objects "origin/$branch..HEAD" | grep -E "\.(mp4|flac)$"
Great when something feels off and you want facts instead of guesses.
git diff --cached --name-status
git diff
git log --oneline origin/$(git branch --show-current)..HEAD
git log --all -- '*.mp4' '*.flac'