Here is a set of some git snippets, useful in some way.
Delete merged branches
Code
git branch --merged | grep -v '\*\|master\|main\|develop' | xargs -n 1 git branch -d
Git log
Alias:
git config --global alias.graph-log 'log --pretty=oneline --abbrev-commit --graph'Use:
git graph-log
Alias:
git config --global alias.graph-log 'log --pretty --oneline --graph --abbrev-commit --relative-date'Use:
git graph-log
Refresh with development branch
Alias:
git config --global alias.dev '!f() { git add . ; git stash push --message "stash_dev" ; git checkout development ; git pull origin development ; git stash apply stash^{/stash_dev} ; }; f'Use:
git dev
Commit no verify
Alias:
git config --global alias.cnv 'commit --no-verify'Use:
git cnv --message "..."
Push no verify
Alias:
git config --global alias.pnv 'push --no-verify'Use:
git pnv {origin} {branch}
Git config user
git config --local user.email "john.doe@mail.com"
git config --local user.name "John Doe"
Git hook
Git hook to validate branch name
#!/bin/sh
remote="$1"
url="$2"
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(main|master|develop|development|((feature|bugfix|bug-fix|bug|fix|release|hotfix|hot-fix)+\/{1,1}[a-zA-Z0-9_.-]+))$"
message="The branch name \"$local_branch\" is not correct. Branch names must accomplish the following convention: \"$valid_branch_regex\". The branch should be renamed a valid name and try again."
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
fi
exit 0
