DEV Community

Cover image for Git Workflows That Won’t Make You Cry: A Dev’s Cheat Sheet
Peter Parser
Peter Parser

Posted on

Git Workflows That Won’t Make You Cry: A Dev’s Cheat Sheet

You know the feeling. You’re three commits deep, something broke, and now your git log looks like a conspiracy theory. Breathe.

You don’t need AI to fix your Git mess. You need a boring, repeatable workflow. Let’s build one.


1. The Golden Rule: One Thing at a Time

Never mix a bug fix with a new feature. Never mix formatting changes with logic changes.

Why?
When you revert, you’ll lose both. When you review, you’ll hate yourself.

Fix:
Make small, atomic commits. If you catch yourself writing “and” in a commit message:

"fix login bug and update README"
Enter fullscreen mode Exit fullscreen mode

Stop. Split it.


2. The Basic Sanity Workflow (Solo Devs / Small Teams)

This works for 90% of daily work.

# Start from a clean main
git checkout main
git pull origin main

# Create a feature branch
git checkout -b feature/short-description

# Do your work, commit often
git add .
git commit -m "add: specific change"

# Rebase before merging (clean history)
git checkout main
git pull origin main
git checkout feature/short-description
git rebase main

# Fast-forward merge
git checkout main
git merge --ff-only feature/short-description
git push origin main
Enter fullscreen mode Exit fullscreen mode

Why rebase?
It avoids messy “merge bubbles” and keeps history clean and linear.


3. The “Oh No, I Committed to Main” Escape

We’ve all done it.

If you haven’t pushed:

git reset HEAD~1 --soft
Enter fullscreen mode Exit fullscreen mode

If you already pushed (and no one else pulled):

git reset HEAD~1 --hard
git push --force-with-lease
Enter fullscreen mode Exit fullscreen mode

Pro tip:
--force-with-lease > --force (safer, won’t overwrite others’ work).


4. Fix a Typo in the Last Commit

No need for "oops typo" commits.

git add fixed-file.js
git commit --amend --no-edit
Enter fullscreen mode Exit fullscreen mode

If already pushed:

git push --force-with-lease
Enter fullscreen mode Exit fullscreen mode

(Only if you're the only one using that branch.)


5. Branch Naming That Doesn’t Suck

Keep it consistent and readable:

feature/add-payment
bugfix/fix-login-null
hotfix/update-ssl-cert
chore/update-deps
docs/api-authentication
Enter fullscreen mode Exit fullscreen mode

Prefixes:

  • feature/ – new functionality
  • bugfix/ – non-urgent fixes
  • hotfix/ – production issues
  • chore/ – tooling/config
  • docs/ – documentation

6. Undo Almost Anything with reflog

Git quietly tracks everything.

git reflog
git reset <commit-hash> --hard
Enter fullscreen mode Exit fullscreen mode

Think of it as Ctrl + Z for Git.


7. Pull Request Workflow (Teams)

main
  └── develop
       └── feature/xyz
Enter fullscreen mode Exit fullscreen mode

Rules:

  • Don’t push directly to main or develop
  • PR: feature → develop
  • Merge with --no-ff
  • Periodically merge develop → main for releases

8. One Alias That Actually Helps

Add this to ~/.gitconfig:

[alias]
    tree = log --graph --pretty=oneline --abbrev-commit --all
    unstage = reset HEAD --
    last = log -1 HEAD
    co = checkout
    br = branch
    st = status
Enter fullscreen mode Exit fullscreen mode

Now run:

git tree
Enter fullscreen mode Exit fullscreen mode

…and enjoy a clean visual history.


When to Break These Rules

  • Hotfix in production?
    Commit directly to main (but communicate it).

  • Tiny doc fix?
    Fine to commit directly if you’re solo. Use [ci skip].

  • Solo dev life?
    Do what you want—but build good habits anyway.


Final Thought

Git isn’t about knowing 100 commands.

It’s about knowing a few commands really well and following a predictable workflow.

Stop fighting your version control. Copy this, tweak it for your team, and get back to shipping.


— A dev who has lost code exactly twice and learned both times

Top comments (2)

Collapse
 
mdenda profile image
Matías Denda

Hey!! Great article!!!

Collapse
 
ajay_mudettula profile image
Peter Parser

Really appreciate you reading it !