Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 10, 2022 05:04 pm GMT

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

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 messagesome long commit body

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

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 mutationWas checking for mutation result BlaBlaResult, instead of BlaResult.

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

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:

BranchApprovals
main1
production2

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

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

git config --global fetch.prune true

Remove all tags that are not on remote

git tag -l | xargs git tag -dgit fetch --tags

Autocorrect git

git config --global help.autocorrect 1

Remove multiple files after deleting them from the disk

git ls-files --deleted -z | xargs -0 git rm

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

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

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


Original Link: https://dev.to/woovi/woovi-git-best-practices-1i0e

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To