The 4 Things Every New Git User Does Wrong

There is already a lot of complexity in a project. Using Git to store the project shouldn’t be another complexity. But Git is not teach as much as other tools as it should be. Here are the fundamental things every new Git user should know when starting to use it.

Create a new commit to add unit tests

A commit must contain a single feature. Unbreakable.

And the unit tests must never be separte from the feature itself.
Feature and unit tests go togheter.

Create a new commit with the Code Review feedbacks

After a Code Review, the new developers create a new commit with the feedbacks.

The feedbacks concern the previous commit. The feedbacks must replace the previous commit.
Otherwise, I have one commit with incorrect content and one commit with sytanxis corrections (no real value).

To do so, I use:

git commit --amend

Don’t use slash when naming the branches

When naming a branch, I can use different levels separate with slash.

The first level is the origin of the feature: feat, bug, test, refacto…

The second level is the core block or the ID of the issue tracker: front, database, controllers, jira-123, gitlab-456…

And the third level is a small name of the feature separate with hyphens: new-page, update-entity…

Resulting: feat/jira-123/new-page

Proper commit messages

Commit messages are the only way to know why a commit was created.

Invest time in writing good commit messages.

I use to write multi-lines messages. I can do it with the command git commit (without the -m option).
This will open a text editor where I can add multiple lines for my commit message.

In the first line, I include the ID of the issue tracker, followed by a quick description of the cause (not the changes).

I leave a blank line and add a first block with a detailed description of the modifications I’ve done.

I leave another blank line and add a second block with the side effects my development can have.

Then, one last block what I may not finished. The refactorings needed. The TODOs.

And finally, the latest block with links, reading…

If you want to learn more about good quality code, make sure to follow me on Youtube.

My New ebook, How to Master Git With 20 Commands, is available now.

Leave a comment

A WordPress.com Website.