Git Commands Every Developer Should Know (The Daily 15)
The Git commands you actually use every day, from staging and committing to branching, merging and undoing mistakes, with plain-English explanations.
- →The daily Git core is small: status, add, commit, push, pull, branch, checkout and merge.
- →git status is the command you'll run most, it shows what's staged, changed and untracked.
- →Branches let you work on features without touching the main code; merge brings them back.
- →You can undo almost anything in Git: unstage, amend, revert or reset.
- →git pull before you push to avoid conflicts with your teammates' work.
Git has hundreds of commands, but you use maybe fifteen every day. Learn these well and you'll handle 95% of real work confidently, without memorizing the manual. Here are the daily Git commands grouped by what you're trying to do.
Starting out
git init # start tracking a new project
git clone <url> # copy an existing repo to your machine
git status # what's changed, staged, or untracked (run this a LOT)Saving your work (staging and committing)
Git saves in two steps: stage the changes you want, then commit them as a snapshot with a message.
git add . # stage all changes
git add file.js # stage one file
git commit -m "Add login" # commit staged changes with a message
git log --oneline # see the history compactlygit status is your best friend. Run it before and after almost every command to see exactly what state your repo is in. It prevents most mistakes.
Working with the remote
git pull # fetch and merge others' changes (do this before you push)
git push # send your commits to the remote (GitHub, etc.)Always pull before you push. If a teammate pushed while you were working, pulling first merges their changes and avoids a rejected push.
Branching and merging
Branches let you build a feature in isolation, then merge it back into main when it's ready. This is the heart of team workflows.
git branch feature-x # create a branch
git checkout feature-x # switch to it
git switch -c feature-x # create AND switch (newer syntax)
git merge feature-x # merge it into your current branchUndoing mistakes
Almost nothing in Git is permanent. Here's how to fix the common oops moments:
| You want to... | Command |
|---|---|
| Unstage a file (keep the changes) | git restore --staged file.js |
| Discard local changes to a file | git restore file.js |
| Fix the last commit message | git commit --amend |
| Undo a commit but keep the changes | git reset --soft HEAD~1 |
| Undo a pushed commit safely | git revert <commit> |
reset rewrites history (use it before pushing). revert adds a new commit that undoes an old one (safe after pushing). When in doubt on a shared branch, revert.
Seeing what changed
git diff # unstaged changes
git diff --staged # staged changes
git log --oneline --graph # visual history with branchesThe short version
The daily Git you need: status to see state, add and commit to save, pull and push to sync, branch/switch and merge to work on features, and restore/reset/revert to undo. Master these fifteen and you'll rarely need to look anything else up.
Frequently asked questions
What are the most important Git commands to learn?+
The daily core is: git status (see changes), git add and git commit (save work), git pull and git push (sync with the remote), git branch/switch and git merge (work on features), and git restore/reset/revert (undo mistakes). These handle the vast majority of real work.
What's the difference between git reset and git revert?+
git reset moves your branch back and can rewrite history, use it for local commits you haven't pushed. git revert creates a new commit that undoes a previous one without rewriting history, which is safe on shared branches. On a branch others use, prefer revert.
How do I undo the last commit in Git?+
To undo the last commit but keep the changes staged, use git reset --soft HEAD~1. To just fix the commit message, use git commit --amend. If the commit was already pushed to a shared branch, use git revert <commit> to undo it safely with a new commit.
Why should I run git pull before git push?+
Pulling first fetches and merges any commits your teammates pushed while you were working. If you push without pulling and the remote has new commits, Git rejects your push. Pulling first resolves that and keeps everyone's history in sync.
How do I create and switch to a new branch?+
Use git switch -c branch-name to create a new branch and switch to it in one step (the newer syntax), or the older git branch branch-name followed by git checkout branch-name. Branches let you work on a feature without affecting the main code.
I build fast, SEO-ready sites and rank them on Google and AI search.