lobo_tuerto's notes
for greatly improving DX
Blog
Notes
About

Basic Git configuration

Let's customize the git configuration for an improved DX.

📅Date10 June 2018Updated28 August 2021
🏷️
devgit

Set up our user and email:

git config --global user.name "Your name goes here"
git config --global user.email "your@email.goes.here"

Always git pull with rebase:

git config --global pull.rebase true

Let’s have colored output for git status and git diff:

git config --global color.ui "auto"

Enable the automatic detection of CPU threads to use when packing repositories:

git config --global pack.threads "0"

Here are some very useful aliases.
Let’s add them to our ~/.gitconfig:

[alias]
  l = log --oneline --decorate --graph

  ll = log --graph --abbrev-commit --decorate \
  --format=format:'%C(yellow)%h%C(reset) %<(14)%C(brightred)%ar%C(reset) \
  %C(white)%s%C(reset) %C(magenta) %an%C(reset)%C(bold yellow)%d%C(reset) \
  => %C(brightcyan)%G?%C(reset)'

  lll = log --graph --abbrev-commit --decorate \
  --format=format:'%C(yellow)%h%C(reset) %C(brightred)%ai%C(reset) \
  %C(white)%s%C(reset) %C(magenta) %an%C(reset)%C(bold yellow)%d%C(reset) \
  => %C(brightcyan)%G?%C(reset)' \
  --branches

  co = checkout
  ci = commit
  cis = commit -S -s
  man = help
  h = help
  a = add
  f = fetch
  d = diff
  dc = diff --cached
  dt = difftool
  dtc = difftool --cached
  ds = diff --stat
  dsc = diff --stat --cached
  s = status --short --branch
  b = branch
  pfl = push --force-with-lease

[credential]
  helper = cache

[diff]
  algorithm = histogram

Define a global .gitignore file:

git config --global core.excludesfile ~/.gitignore_global

Let’s use it to ignore vscode project files and files generated by the ElixirLS plugin:

echo ".vscode/" >> ~/.gitignore_global
echo ".elixir_ls/" >> ~/.gitignore_global

Set the default branch name for your new repos:

git config --global init.defaultBranch main

Dealing with line endings:

git config --global core.autocrlf input
git config --global core.safecrlf true

Easy peasy, lemon squeezy! 🍋


Got comments or feedback?
Follow me on
rev-7175614