Skip to content

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 main

Prefer 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/main

Push your branch ​

bash
git push -u origin HEAD
# same as:
git push -u origin feature/login-form

Later pushes (tracking set):

bash
git push

Switch branches ​

bash
git switch main
git switch feature/login-form
git switch -                # previous branch
git branch -vv              # local + tracking

What’s different? ​

bash
git diff                    # unstaged
git diff --staged           # staged
git diff main...HEAD        # your branch vs main

Undo 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/main

PR-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/GitLab

Clean merged branches ​

bash
git switch main
git pull
git branch --merged
git branch -d feature/old-thing
git fetch -p                # prune deleted remotes

Quick log views ​

bash
git log --oneline --graph --decorate -20
git log --author="You" --since="2 weeks ago" --oneline