A simple tutorial (and reminder) of how I like to configure Git to improve workflow.
There are three levels of configs on git:
--system
- all computer users--global
- only current user--local
- only this repo
To check the current configuration use the git config --list
command.
init.defaultbranch=main
user.name=Gabriela Carvalho Camilo
user.email=gabccamilo.dev@gmail.com
core.editor=vim
You can add custom shortcuts for git commands using the [alias]
tag in the configuration file as shown in the example bellow:
s = !git status -s # -s for simpler output
c = !git add --all && git commit -m # add and commit with one command. WARNING!!! Be sure you really want to add everythig before using it to commit!
l = !git log --oneline # -oneline for simpler output
When visualizing many commits, git log
can be a little overwhelming so, I like to customize its output to improve data visualization. To achieve this goal the argument --pretty=format:
can be used alongside the desired format, as shown in the example below (good for darker themes on the terminal):
$ git --no-pager log --pretty=format:'%C(yellow)%h%C(red)%d %C(reset)%s - %C(cyan)%cn, %C(green)%cr'
The complete list of arguments can be found in the git documentation, and remember you can create a shortcut for this huge command line in the git configuration file.