Git Tips
Git style
For Git we follows this guides
When you change a lot of files, move folder, or run linters, that should be in separate commit (or even separate pull request) and put the command in commit message
git mv test/fixtures spec
git commit -am"git mv test/fixtures spec"
# or
standardrb --fix spec
git commit -am"standardrb --fix spec"
Code review
For code review
When working on some task, for example issue 123 than we usually create a branch
that looks like i#{issue number}_#{description}
and use commit number at the
end git commit -m'#{some description} ##{issue number}
For example
git checkout -b i123_add_test_for_signup
# make changes
git commit -m'Add test for signup #123`
git push -u origin HEAD
Gitflow
For big projects we follow GitFlow
so all PR are done on develop
branch. Only i123_hotfix_something
branch
start from main
and merged back to develop
and main
.
Nice tutorial:
Github cli
We also use gh cli
# create PR and put commit messages as comment
gh pr create --fill
# assign reviewers
gh pr edit
# rebase and delete local and remote branch
gh pr merge -r -d
Remove all branch on which I’m not the author
#!/bin/bash
current_user=$(git config user.email)
# Remove all local branches on which I'm not the author of the tip
for branch in $(git branch --format='%(refname:short)'); do
if [[ "$branch" =~ ^(main|develop|master)$ ]]; then
continue
fi
author=$(git log -1 --format='%ae' $branch)
if [ "$author" != "$current_user" ]; then
echo removing -$branch- $author
git branch -D $branch
echo
fi
done