The git commands you actually use, organised
Git has hundreds of commands, but day-to-day work runs on a couple dozen. This reference groups the essentials by area — setup, staging, committing, branching, integrating, remotes and undo — with the common flags and a one-line description for each, so you can find the right command and its key options fast.
How it works
Git tracks three places: the working tree (your files), the index/staging area (what the next commit will contain) and the commit history. Most commands move changes between these:
git add -p # stage selected hunks into the index
git commit -m "message" # record the index as a commit
git switch -c feature # create and move onto a new branch
git rebase main # replay feature commits onto the latest main
git push -u origin feature --force-with-lease
Remote commands (fetch, pull, push) sync that history with a server, and
undo commands (reset, revert, restore, reflog) walk it back when
something goes wrong.
Tips and notes
- Stage precisely with
git add -pso each commit is a coherent, reviewable change. - Prefer
git reverton shared branches; reservegit reset --hardfor local cleanup you are sure about. - Use
git push --force-with-lease, never bare--force, after rebasing. - Keep
git reflogin mind — it is your safety net for recovering commits that a reset or rebase appeared to delete.