DEV Community

Alex Chen
Alex Chen

Posted on

The Git Workflow Every Solo Developer Needs (2026)

The Git Workflow Every Solo Developer Needs (2026)

Stop committing directly to main. This system prevents 90% of "oh crap" moments.

The Problem

We've all done it:

# Quick fix, no time for branches
git add -A
git commit -m "fixed bug"
git push origin main

# ... 2 hours later ...
# Oh no, that broke something else
Enter fullscreen mode Exit fullscreen mode

When you're solo, there's no code review partner. You need your own process to be your safety net.

My Workflow

Branch Strategy

main (protected — never push directly)
  ├── feature/xxx     (new features)
  ├── fix/xxx         (bug fixes)
  └── refactor/xxx    (code cleanup)
Enter fullscreen mode Exit fullscreen mode

Pre-Push Hook (My #1 Safety Net)

#!/bin/sh
# .git/hooks/pre-push — runs before every push

# 1. Block direct pushes to main/develop
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
  echo "❌ Direct pushes to '$BRANCH' are blocked!"
  echo "   Create a feature branch and merge instead."
  exit 1
fi

# 2. Check for secrets
if git diff --cached --name-only | grep -qiE '\.env$|credentials|secret'; then
  echo "⚠️  Possible secret file detected!"
  exit 1
fi

# 3. Run tests if available
if [ -f "package.json" ] && grep -q '"test"' package.json; then
  npm test || { echo "❌ Tests failed"; exit 1; }
fi

echo "✅ All checks passed"
exit 0
Enter fullscreen mode Exit fullscreen mode

Make executable: chmod +x .git/hooks/pre-push

Useful Aliases

# ~/.gitconfig
[alias]
  s = status -sb
  lg = log --oneline --graph --decorate
  undo = reset --soft HEAD~1
  amend = commit --amend --no-edit
  save = stash push -u -m 'WIP'
  pop = stash pop
  clean-branches = "!git branch --merged | grep -v '\\*\\|main\\|master' | xargs git branch -d"
Enter fullscreen mode Exit fullscreen mode

Handling Mistakes

"I pushed broken code to main"

# Option 1: Revert (safe, preserves history)
git revert HEAD
git push origin main

# Option 2: If you MUST rewrite history
git reset --hard HEAD~1
git push --force-with-lease origin main
Enter fullscreen mode Exit fullscreen mode

"I committed to the wrong branch"

git branch new-branch
git reset --hard HEAD~N  # N = number of commits to move back
git checkout new-branch   # Your work is here now
Enter fullscreen mode Exit fullscreen mode

Release Workflow

npm version patch/minor/major  # Updates package.json, creates tag
git push --follow-tags        # Pushes commits and tags
npm publish                   # Publishes to registry
Enter fullscreen mode Exit fullscreen mode

Follow @armorbreak for more developer productivity tips.

Top comments (0)