Git — everyday
Everyday The 90% loop on client work.Update from remote
bash
git fetch origin
git status
# merge remote into current branch
git pull
# or explicit:
git pull origin mainPrefer fetch + inspect when the branch is messy:
bash
git fetch origin
git log --oneline HEAD..origin/main
git merge origin/main
# or: git rebase origin/mainPush your branch
bash
git push -u origin HEAD
# same as:
git push -u origin feature/login-formLater pushes (tracking set):
bash
git pushSwitch branches
bash
git switch main
git switch feature/login-form
git switch - # previous branch
git branch -vv # local + trackingWhat’s different?
bash
git diff # unstaged
git diff --staged # staged
git diff main...HEAD # your branch vs mainUndo carefully (safe-ish)
bash
# discard unstaged changes in one file
git restore path/to/file
# unstage (keep working tree)
git restore --staged path/to/file
# throw away local commits not pushed (destructive)
git reset --hard origin/mainPR-oriented flow
bash
git switch main
git pull
git switch -c fix/header-spacing
# ... work ...
git add -A
git commit -m "fix: tighten header spacing"
git push -u origin HEAD
# open PR on GitHub/GitLabClean merged branches
bash
git switch main
git pull
git branch --merged
git branch -d feature/old-thing
git fetch -p # prune deleted remotesQuick log views
bash
git log --oneline --graph --decorate -20
git log --author="You" --since="2 weeks ago" --oneline