Skip to the content.

11 Expert Tips for Efficient Committing

Explore 11 essential tips for mastering code commits, including effective messaging, managing file counts, and using shortcuts to streamline your workflow. Here’s a guide to enhance your commit practices for a better development experience.

Local and Remote Commits

Understanding the difference between local and remote commits is crucial:

Keep your local and remote repositories in sync:

Conflicts may arise during merges if there are discrepancies in commit history. 🔄

How Many Files to Include in a Commit

Example of Commits

Example of Few Files Split into More Commits

Smaller, well-defined commits make it easier to track and revert specific changes:

Few Files Split

Git Commit Command Tips

Basic Git Commit

Commit with Message Inline

Git Add and Commit Simultaneously

Commit Amendment

Tips for Writing Good Commit Messages

  1. Use Action-Oriented Verbs:
    • E.g., Improve, Optimize, Update, Implement
  2. Be Clear and Specific:
    • E.g., Improve navigation bar responsiveness, Optimize database query performance
  3. Avoid Ambiguity:
    • Specify what was changed and why.
  4. Format Consistently:
    • Title (50 characters max) and description (72 characters per line).
  5. Provide Additional Context:
    • Use comments or descriptions if needed.

What Not to Write in a Commit Message

Using VS Code Shortcuts for Commits

  1. Configure Shortcuts:
    • Go to File > Preferences > Keyboard Shortcuts (CTRL + K + S).
  2. Assign Shortcuts:
    • Double-click on Git: Commit and set your preferred shortcut.
  3. Commit from VS Code:
    • Use the shortcut to open the commit message box.

VS Code Shortcut

Editing Git Messages in VS Code

Editing Git Messages

References

Callback

Ref: Adarsh Rai - Medium