DEV Community 👩‍💻👨‍💻

Cover image for Woovi Git Best Practices
Danilo Assis for Woovi

Posted on

Woovi Git Best Practices

We seek to follow a culture of good practices related to our development process with git.

Below you will find some of the most used practices.

Git message

Follow these 7 rules:

  1. Separate the head from the body with a blank line
  2. Limit the headline to 50 characters
  3. Do not end the headline with a period
  4. Use the imperative mood in the headline (example: "Create" instead of "Created")
  5. Wrap the body at 72 characters
  6. Use the body to explain what and why vs. how

Really good article about those rules: https://chris.beams.io/posts/git-commit/

Commitlint

Some of our projects uses commitlint with the conventional config.

This means you need to create commit messages using the following format:

type(subject): commit message
Enter fullscreen mode Exit fullscreen mode

Keep in mind this will go to the changelog, so create a concise commit message related to your changes, remember that you can always use the commit message body to say more details about your changes:

type(subject): commit message

some long commit body
Enter fullscreen mode Exit fullscreen mode

Usually to see available types, check the commitlint.config.js file on the root of your project, the type-enum key.

Some scenarios:
Fixed some UI on User Evolution on Woovi

style(user-evolution): fix the wrong color on feedback received chart
Enter fullscreen mode Exit fullscreen mode

Fixed some wrong code on groups that were causing form submissions to always return errors:

fix(groups): add new Group form checking from the invalid return from mutation

Was checking for mutation result BlaBlaResult, instead of BlaResult.
Enter fullscreen mode Exit fullscreen mode

Since fix(subject) already says it's a fix, you don't need to start the commit message with fix blah.

Another scenario is updating schemas, trying to update schemas as a separate commit, and using the commit message:

chore(schemas): update schemas
Enter fullscreen mode Exit fullscreen mode

Branch naming

Try to stick to the format [kind-of-change]/[what-is-being-changed] whenever possible.

Example: fix/user-name-during-login, improvement/login-screen, feature/charge-customer-screen.

Pull Requests

To modify anything on main or production, always open a PR first.

Many approvals, from Woovi devs, are required to merge a PR:

Branch Approvals
main 1 ✅
production 2 ✅

Useful git commands

Remove all merged branches from a local repo

git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch -d
Enter fullscreen mode Exit fullscreen mode

Or if you want to just remove the references to remote when they are deleted

git config --global fetch.prune true
Enter fullscreen mode Exit fullscreen mode

Remove all tags that are not on remote

git tag -l | xargs git tag -d
git fetch --tags
Enter fullscreen mode Exit fullscreen mode

Autocorrect git

git config --global help.autocorrect 1
Enter fullscreen mode Exit fullscreen mode

Remove multiple files after deleting them from the disk

git ls-files --deleted -z | xargs -0 git rm
Enter fullscreen mode Exit fullscreen mode

Git aliases

[alias]
    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    co = checkout
    ec = config --global -e
    cob = checkout -b
    cm = !git add -A && git commit -m
    st = status
Enter fullscreen mode Exit fullscreen mode

To add this alias to your git command line, copy and paste it to ~/.gitconfig.

Apply the changes introduced by some existing commits: git cherry-pick

The main idea is to transfer a commit from branch A to branch B.

When to use?
Let's say you have committed to the wrong branch. A good way to copy and paste this commit to the right branch is to use git cherry-pick.

How to use?
First of all, run git log in the source branch to see the commit sha1. Then, switch to the destination branch and run the following:

git cherry-pick commit_sha1
Enter fullscreen mode Exit fullscreen mode

Where commit_sha1 is the sha1 string of the desired commit. If there aren't any conflicts, the changes will be applied.


Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.

If you want to work with us, we are hiring!


Photo by Roman Synkevych 🇺🇦 on Unsplash

Top comments (2)

Collapse
 
cazevedo profile image
Камило Куньа

👏

Collapse
 
vasanth9 profile image
vasanthkumar

branch naming is really awesome. In my current project , we are only using same branch UI_VasanthChanges from 8 sprints.

🌖🌗🌘 Turn on dark mode in Settings