← Back to Blog

My Git Discipline: How to Keep Your Feature Branches and Commit History Sane

5/23/2025

My Git Discipline: How to Keep Your Feature Branches and Commit History Sane

If you've ever stared at a Git log that looked like a Jackson Pollock painting, you already know the cost of undisciplined version control. Over the past decade, I’ve been the person both untangling and accidentally creating spaghetti histories. What I’ve learned is this: Git is not just a tool — it's a language. And like any language, fluency demands consistency, clarity, and intent.

In this article, I’ll walk you through the Git habits and branch discipline I live by — rules that scale from solo side projects to team-based enterprise systems.

1. Always Branch with Purpose

Rule: Never code directly on main or develop.

Every task, bug fix, or feature should start with a fresh branch. I prefix branches based on purpose:

This creates semantic clarity and makes pull request (PR) scoping predictable.

Pro tip: Use conventional commits for naming and map your branch to Jira, Trello, or GitHub Issues for traceability.

2. Write Commits Like a Changelog

Each commit is a narrative step in your branch's story. Keep them:

Example:

1git commit -m "Fix recipe image crash when file is null"

Don’t be afraid to rewrite history while on a feature branch. That’s what rebase -i is for.

3. Rebase Before You Push (When Solo)

If your branch is local and untouched by others, rebasing keeps your commit history linear and clean.

1git fetch origin git rebase origin/main

I do this before every push. It avoids noisy merge commits and helps with cherry-picking if needed later.

Pro tip: Configure your editor to make interactive rebase (git rebase -i) intuitive and quick.

4. Squash Merge, Don’t Merge Merge

When it's time to merge a feature branch back into main, I always squash — unless it's a long-running integration branch.

git checkout main
git merge --squash feature/recipe-image-upload

This gives you one canonical commit for the feature and keeps the commit log readable.

If your team prefers PR merges via GitHub/GitLab: enable "Squash and merge" as default.

5. Clean Up After Yourself

After merging:

git branch -d feature/recipe-image-upload git push origin --delete feature/recipe-image-upload

Treat your branches like temporary workspaces — not long-term habitats.

6. Use Git Hooks for Preflight Checks

I use pre-commit hooks to:

Tools like Husky or lefthook make this easy.

7. When in Doubt, Stash and Start Over

Your working directory feels wrong? Stash and get back to safety:

git stash push -m "WIP: experimenting with token refresh"

This is your Git “Save Game” button. Come back later — or never.

Final Thoughts

The elegance of Git is not in the commands, but in the habits you form around them. Branch discipline, semantic commits, and thoughtful history curation aren’t just about aesthetics — they save hours of engineering time and earn respect from teammates (and your future self).

If you’re still treating Git like a file backup tool, it’s time to level up.

Write history that matters. Use branches with clarity. Be proud of your Git log.!


Land Your Next $100k Job with Ladders