This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Danilo Assis
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:
- Separate the head from the body with a blank line
- Limit the headline to 50 characters
- Do not end the headline with a period
- Use the imperative mood in the headline (example: "Create" instead of "Created")
- Wrap the body at 72 characters
- 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 message
some 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 mutation
Was 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:
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
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 -d
git 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
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Danilo Assis
Danilo Assis | Sciencx (2022-11-10T17:04:35+00:00) Woovi Git Best Practices. Retrieved from https://www.scien.cx/2022/11/10/woovi-git-best-practices/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.