DEV Community

Cover image for A tip to get a nice git history: let git tell your code story
Juan Vega
Juan Vega

Posted on • Edited on

A tip to get a nice git history: let git tell your code story

If you're new to git, it can be overwhelming to manage your code changes and keep your git history clean. In this post, we'll explore some tips to help you get a nice git history that tells your code story effectively.

Avoid merge commits

Merge commits can make your git history messy and hard to follow. Instead, you can use git rebase to keep your git history linear and make it easier to understand. With git rebase, you can merge changes from one branch onto another and create a clean and concise git history.

All in one, interactive rebase

To use git rebase, you can use the interactive mode (-i) to squash multiple commits into a single commit with a new message. For example, you can run the command git rebase -i HEAD~3 to squash the last 4 commits into a new one with a new message. This will open up an editor where you can choose which commits to squash and edit the commit message. GitHub and GitLab also support squash and merge operation to create a single commit with all your Pull/Merge Request changes.

Use conventional commit

Conventional commit is a specification for adding human and machine-readable meaning to commit messages. By using a conventional commit format, you can make your commit messages more informative and easier to understand. To learn more about conventional commit, you can check out this post which explains what it is and how to use it effectively.

With these tips, you can create a clean and informative git history that tells the story of your code changes effectively. Happy coding!

cover from pexels

Top comments (0)