Git Commands I Use Every Day
I've been using Git for over a decade. Here are the commands that actually matter for daily work.
The Essentials
Check What's Going On
git status
git log --oneline -10
git diff
I run `git status` probably 50 times a day.
Make Commits
git add .
git commit -m "feat: add user authentication"
Or, add and commit in one:
git commit -am "fix: resolve null pointer"
(Only works for tracked files)
Branching
git checkout -b feature/new-thing
git checkout main
git branch -d feature/old-thing
Stay Up to Date
git pull origin main
git fetch --all
Intermediate Moves
Stash
Working on something but need to switch branches?
git stash
git checkout other-branch
# do stuff
git checkout original-branch
git stash pop
Interactive Rebase
Clean up commits before merging:
git rebase -i HEAD~5
Then squash, reword, or reorder commits.
Amend Last Commit
Forgot something?
git add forgotten-file.js
git commit --amend --no-edit
Reset
Undo commits (carefully!):
# Soft: keep changes staged
git reset --soft HEAD~1
# Mixed: keep changes unstaged
git reset HEAD~1
# Hard: discard changes (careful!)
git reset --hard HEAD~1
Useful Aliases
In `~/.gitconfig`:
[alias]
s = status
co = checkout
br = branch
cm = commit -m
last = log -1 HEAD
undo = reset HEAD~1 --mixed
graph = log --oneline --graph --all
Tips
- **Commit often** - Small commits are easier to revert
- **Write good messages** - Future you will thank present you
- **Pull before push** - Avoid merge conflicts
- **Use branches** - Never commit directly to main
Git is one of those tools that rewards investment. Learn it well.