Git: Commands I Actually Use
Not a full reference — just the things I reach for regularly, including the recovery stuff I always forget.
Branch management
git branch # list branches
git checkout -b feature-name # create + switch
git checkout main # switch to main
git branch -d feature-name # delete (safe)
git push origin --delete branch # delete remote
Undoing things
Undo the last commit (keep changes staged)
git reset --soft HEAD^
Undo the last commit (unstage changes)
git reset HEAD^
Hard reset to a specific commit (destructive)
git reset --hard <commit-hash>
git push origin <branch> --force
Real example from my workflow:
git log
git reset --hard d37c4bb36ebbb03e0f3beccb72418e153bf7b367
git push origin feat-country-comparison --force
Fix last commit message
git commit --amend -m "feat(cards): implement auto debit limit feature"
Abort a merge in progress
git merge --abort
Working with feature branches off release
git fetch origin
git checkout -b feature-name origin/release
git push origin feature-name
Submodules (I always forget this)
git submodule init
git submodule update
Move / rename files (tracks history)
git mv src/old-name.ts src/new-name.ts