DEV Community

Suman Bhattarai
Suman Bhattarai

Posted on

1

πŸš€ Mastering Git Best Practices: Clean Workflow for Modern Development

Git is the backbone of almost every modern development workflow.

Yet, many projects suffer from messy commit histories, confusing branches, and lost productivity β€” simply because of poor Git practices.

In this guide, we'll walk through the best Git practices for cleaner, professional development, with examples from real-world mobile app projects.


πŸ“‚ 1. Branching Strategy: Structure Matters

A clear branching model is crucial to avoid chaos when features, bug fixes, and releases are happening simultaneously.

Here’s a simple and effective structure:

Branch Purpose
main Always production-ready
develop Integration branch for features
feature/ For building new features
fix/ For fixing bugs
chore/ Maintenance tasks like refactoring or dependency updates

βœ… Example

If you are adding a new dark mode toggle feature in a mobile app:

git checkout -b feature/dark-mode-toggle
Enter fullscreen mode Exit fullscreen mode

Fixing a crash when opening the Profile Screen:

git checkout -b fix/profile-screen-crash
Enter fullscreen mode Exit fullscreen mode

πŸ“ 2. Writing Great Git Commit Messages

Good commit messages tell a story of your project.

Use the Conventional Commits format to make your messages clear, structured, and machine-readable.

Format:

<type>: <short description>
Enter fullscreen mode Exit fullscreen mode

Where <type> can be:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation changes
  • style: Code formatting, no logic change
  • refactor: Code refactoring without changing behavior
  • test: Adding or fixing tests
  • chore: Maintenance tasks (build, configs)

βœ… Good Examples

git commit -m 'feat: add dark mode support'
Enter fullscreen mode Exit fullscreen mode
git commit -m 'fix: correct crash when navigating to ProfileScreen'
Enter fullscreen mode Exit fullscreen mode
git commit -m 'chore: update React Native to 0.73'
Enter fullscreen mode Exit fullscreen mode

Tip:

Always use imperative mood (like "fix bug" instead of "fixed bug") for consistency.


πŸ“š 3. Keep Commits Small and Focused

One commit = one logical change.

Avoid large "everything-in-one" commits.

Instead, commit after each meaningful change.

βœ… Example

Bad (everything together):

git commit -m 'add profile screen, fix header bug, update navigation'
Enter fullscreen mode Exit fullscreen mode

Good (separate commits):

git commit -m 'feat: create basic ProfileScreen component'
git commit -m 'fix: resolve header navigation bug'
git commit -m 'chore: update navigation library to latest version'
Enter fullscreen mode Exit fullscreen mode

πŸš€ 4. Pull Requests: Reviewable and Ready

Before merging into develop or main, always open a pull request (PR).

A great PR should:

  • Have a clear title and description
  • Link to related tasks/issues
  • Be small and focused (easier to review)

βœ… Example PR title:

feat: implement dark mode toggle
Enter fullscreen mode Exit fullscreen mode

PR Description Template:

What this PR does:

Adds a dark mode toggle in the settings page.

Testing Steps:

  1. Open the app.
  2. Go to Settings β†’ Appearance.
  3. Toggle dark mode on/off.

🧹 5. Clean Up After Merging

Once your branch is merged into develop or main, delete it from the remote repository.

git push origin --delete feature/dark-mode-toggle
Enter fullscreen mode Exit fullscreen mode

This keeps your repository clean and avoids abandoned branches piling up.


✨ Bonus Tips for Professional Git Workflow

  • Sync often: Before pushing, run
  git pull --rebase origin develop
Enter fullscreen mode Exit fullscreen mode

to avoid unnecessary merge commits.

  • Use Draft PRs: If your code isn’t fully ready but you want early feedback.

  • Squash commits: When merging, use "Squash and Merge" to combine multiple small commits into one clean commit on the main branch.

  • Tag releases: Use Git tags to mark production releases.

  git tag -a v1.0.0 -m "First stable release"
  git push origin v1.0.0
Enter fullscreen mode Exit fullscreen mode
  • Automate checks: Add tools like ESLint, Prettier, and testing pipelines so that your PRs are automatically validated.

🎯 Final Thoughts

Mastering Git is not about memorizing commands β€” it's about building habits that lead to clean codebases, happy teams, and faster releases.

By following these best practices, your projects β€” whether solo or team-based β€” will scale more smoothly, avoid technical debt, and stay professional.

Start small, structure your branches, write clear commits, open reviewable PRs β€” and watch your productivity soar πŸš€.

What if your devs could deploy infrastructure like launching a game?

What if your devs could deploy infrastructure like launching a game?

In this session, we'll show how you can build a user-friendly self-service portal for deploying infrastructure with Spacelift, in the flavor of deploying Minecraft servers.

Learn More

Top comments (0)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

πŸ‘‹ Kindness is contagious

Take a moment to explore this thoughtful article, beloved by the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A heartfelt "thank you" can brighten someone's dayβ€”leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay