๐Ÿ“ Git & GitHub

Git Commit Best Practices

P
Author
PyLand Team
๐Ÿ“…
Published
06.05.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
366
๐ŸŒฟ
Level
Medium

A good commit contains one complete change and a message that explains its purpose without requiring the reader to inspect the entire diff.

Rule 1: 1 Commit = 1 Change

# Bad: an entire week's work in one commit
git commit -m "week's work"

# Good: each change separately
git commit -m "feat: add user model"
git commit -m "feat: create login form"
git commit -m "fix: fix email validation"

Atomic commits simplify code review, let you revert a specific change, and make the history readable as documentation.

Rule 2: Write Meaningful Messages

Format: <type>: <what was done>

Commit types:
- feat โ€” new feature
- fix โ€” bug fix
- docs โ€” documentation
- refactor โ€” refactoring
- test โ€” tests
- chore โ€” dependencies, configs

# Good
feat: add two-factor authentication support
fix: fix 500 error on empty email
docs: update API endpoint documentation

# Bad
update
fix
done

Rule 3: Commit Working Code

Before committing:
1. Run the code โ€” does it work?
2. Do tests pass?
3. Does the linter pass?

If you need to save unfinished work:

git stash      # temporarily hide changes
git stash pop  # bring them back

Rule 4: Review the Diff Before Committing

git diff --staged  # see what will go into the commit

Common mistakes: committing console.log(), .env with passwords, accidentally deleting important code.

Rule 5: Use .gitignore

# .gitignore
node_modules/
__pycache__/
.env
*.log
.DS_Store
dist/

Create .gitignore at the start of the project โ€” before the first commit.

Conventional Commits

The industry standard:

<type>[optional scope]: <description>

[optional body]
feat(auth): add two-factor authentication
fix(api): handle null values in user endpoint
docs(readme): update installation instructions
refactor(payment): simplify checkout logic

Scope (optional) narrows the area of change: auth, api, ui, db.

Pre-Commit Checklist

  • Code runs and works
  • Tests pass
  • Diff reviewed โ€” everything looks right
  • Commit message is meaningful
  • No secrets (passwords, tokens)
  • No debug print / console.log
  • .gitignore is configured

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Undo and Revert in GitHub Desktop: Fix Mistakes Wโ€ฆ

A commit is not a point of no return. GitHub Desktop lets you rebuild a...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 359
๐Ÿ“

History, Diffs, and Web Commits on GitHub

GitHub lets you read repository history, inspect individual commit diffs, view the history of one...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 312
๐Ÿ“

Your First Git Commit

Your first commit starts with initializing a repository, configuring the author identity, and selecting the...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 343
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Git & GitHub Desktop: Teamwork Without the Pain Open course curriculum