"Vibe coding" is that state where you are in the flow, writing code calmly, without stress or panic. Your Git workflow should support this state, not fight against it. Good practices are not bureaucratic rules. They are habits that make development smoother, collaboration easier, and mistakes recoverable.
The developers who seem to never have Git problems are not luckier than you. They just have better habits. This lesson teaches those habits.
The daily workflow
Starting your day
Begin every coding sessionWhat is session?A server-side record that tracks a logged-in user. The browser holds only a session ID in a cookie, and the server looks up the full data on each request. the same way:
# Get up to date with main
git checkout main
git pull
# Create a feature branch with a descriptive name
git checkout -b feature/user-authentication| Branch prefix | When to use | Example |
|---|---|---|
feature/ | New functionality | feature/search-bar |
fix/ | Bug fixes | fix/login-null-pointer |
hotfix/ | Urgent production fixes | hotfix/payment-crash |
chore/ | Maintenance tasks | chore/update-dependencies |
refactor/ | Code restructuring | refactor/extract-auth-module |
During development: commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. early, commit often
The golden rule of Git: small, frequent commits beat large, rare commits.
The wrong way:
# Work for 6 hours, edit 15 files
git add .
git commit -m "update"The right way:
# Implement one thing, commit it
git add src/validation.js
git commit -m "feat: add email validation function"
# Implement the next thing, commit it
git add src/auth.js
git commit -m "feat: implement bcrypt password hashing"
# Add tests, commit them
git add tests/auth.test.js
git commit -m "test: add authentication unit tests"Why small commits matter:
| Benefit | Explanation |
|---|---|
| Easier review | PRs with 50 lines get thorough review; PRs with 500 get "LGTM" |
| Easier revert | Undo one specific change without losing everything |
| Easier debugging | git bisect finds bugs faster with more commits |
| More save points | Lose at most 30 minutes of work, not 6 hours |
When context switching strikes
An urgent bug interrupts your feature work. Do not commit half-finished code:
# Save your current work
git stash push -m "WIP: authentication form validation"
# Fix the urgent bug
git checkout main
git checkout -b hotfix/critical-login-bug
git add src/auth.js
git commit -m "fix: correct null pointer in login"
git push -u origin hotfix/critical-login-bug
# Return to your feature
git checkout feature/user-authentication
git stash popBefore pushing: sync with the team
# Fetch latest changes
git fetch origin
# Integrate them
git rebase origin/main
# Push your branch
git push -u origin feature/user-authenticationWriting good commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. messages
Commit messages are documentation. They communicate what changed and why.
The conventional commit format
<type>: <short description>| Type | Meaning | Example |
|---|---|---|
feat | New feature | feat: add user registration |
fix | Bug fix | fix: correct password validation |
docs | Documentation | docs: update API reference |
style | Code formatting | style: fix indentation |
refactor | Code restructuring | refactor: extract auth logic |
test | Adding tests | test: add login flow tests |
chore | Maintenance | chore: update dependencies |
Good messages:
git commit -m "feat: implement JWT authentication middleware"
git commit -m "fix: resolve race condition in user lookup"Bad messages:
git commit -m "update" # Too vague
git commit -m "fix" # No context
git commit -m "WIP" # Not descriptive
git commit -m "asdf" # Not a messageThe pre-commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. checklist
Before every commit, run through this mental checklist:
# Stage your files
git add src/auth.js src/auth.test.js
# Review what you are about to commit
git diff --staged
# If it looks good, commit
git commit -m "feat: add JWT authentication"verbose = true under [commit] in your ~/.gitconfig. This makes it easy to write accurate messages.Common mistakes to avoid
Committing to main directly
# Bad: bypasses code review
git checkout main
git add .
git commit -m "quick fix"
git push
# Good: creates a reviewable PR
git checkout -b fix/quick-bug
git add src/nav.js
git commit -m "fix: correct navigation link"
git push -u origin fix/quick-bugCommitting secrets
# Bad: API keys in the repo forever
git add .env
git commit -m "add config"
# Good: use .gitignore
echo ".env" >> .gitignore
git add .gitignore
git commit -m "chore: ignore environment files"If you accidentally commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. secrets, rotate them immediately. Assume they are compromised the moment they are pushed.
Giant commits
# Bad: one commit with everything
git add .
git commit -m "feature complete + tests + docs + fixes"
# Good: logical separation
git add src/payment.js
git commit -m "feat: implement payment processing"
git add tests/payment.test.js
git commit -m "test: add payment flow tests"Useful Git aliases
Save time with shortcuts in your ~/.gitconfig:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.last "log -1 HEAD"
git config --global alias.please "push --force-with-lease"Now you can type git st instead of git status, git lg for a visual log, and git please for a safe force pushWhat is force push?A destructive Git push that overwrites the remote branch history with your local version, which can break teammates' work if they already pulled the original..
Quick reference
| Practice | Why it matters |
|---|---|
| Commit early, commit often | More save points, easier debugging |
| Small, focused commits | Easier to review and revert |
| Conventional messages | Readable history, changelog generation |
| Feature branches | Isolation, code review, stable main |
| Pull before push | Fewer conflicts, smoother collaboration |
| Stash for interruptions | Clean context switching without WIP commits |
| Review before committing | Catch mistakes before they enter history |
| No secrets in commits | Security, no credential leaks |