
Git: A Good Commit & How To Use It Daily
por Jonathan Fontes, Backend Developer at Monday
Designed to handle every type of projects, Git is a free and open source distributed version control system widely used for software development. Easy to learn and having a tiny footprint with lightning fast performance, Git features cheap local branching, convenient staging areas and multiple workflows.
Summing up, Git is basically about composing and saving snapshots of the project and then comparing and working with those snapshots. This will be your basic workflow, most of the time:
1) You will use git add to start tracking new files and to stage changes to already tracked files;
2) Also, you will use git status and git diff to see what has been modified and staged;
Finally, git commit to record your snapshot into your history.
Best Practices to Write a Good Commit
A good commit is fundamental for numerous reasons. It stores the current contents of the index along with a log message from the user describing the changes. It’s important to write it correctly, once it will inform your colleagues about what you are doing, how and why, either it’s a silly bug or just a fresh Monday morning.
According to Chris Beams’ outline, to write a really good commit you need to:
· Separate subject from body with a black line
· Limit the subject line to 50 characters
· Capitalize the subject line
· Do not end the subject line with period
· Wrap the body at 72 characters
· Use the body to explain what and why vs how
The most important point above is the last one. You must know exactly what you are doing, why you are doing it and how you are doing it. If you take time to reflect about this three questions, you will end up with better knowledge of your solution and analyse if it is the best one for that particular problem.

For example:
> git add readme.txt js/submit.js
> git commit -m “Patched validation form when submitted
>
> This was happening when clicking on the save button. I made the fix
> on submit event because it is the proper place to handle/listen
> submit event.”
At Monday, when arriving in the morning, the first thing our developers do is stash save things on our git locally, pull from Branch Development and, then, apply stash things up to continue programming. This is our normal day and here’s a little checklist step by step:
1. First Stash.
> git stash save
2. Pull from your development branch
> git pull origin development
3. Then, apply your development
> git stash apply
Then, you are ready to continue your work.
Every Git repository needs, at least, three types of branches: Development, Production and one for each Bug or Featured.
The Development branch is your special place and where all the magic happens, also known as “Staging” or “QA”. When a bug appears, you should make a branch with a specific name like “Bug-#094” or “Bug-Submit-Handler”. After fixing it, you need to merge into the Development branch. After passing all the tests, then you can push into Production Branch.
Summarizing, Git is one of the best tools to work as a team, as it is powerful, easy to use and, for advanced users, a complex tool to make another workflow to handle all types of situation.
Thank you for reading
We really do want to hear from you! Get in touch
Monday is a full service digital and interactive agency based in Lisbon. Weʼre a team of designers, builders & thinkers who craft digital experiences. Clients include: Snickers, Red Bull, Twix, Philips, M&M’s