lobo_tuerto's notes
Basic Git configuration
For the best version control system
Published on
2018 / 06 / 10
Updated on
2020 / 12 / 30
Tags
manjarogit
Versions
manjaro i3:20git:2
v1.1.25

§ Introduction

If you are a Manjaro Linux user, then you already have Git in your machine.

If you are an Ubuntu user, install it with:

sudo apt install git

You can check it’s working with this:

git --version
# git version 2.29.0

Let’s proceed with some basic setup, so we are able to initialize new projects and make commits.

§ User and email

Git will use this data to mark any commits you create:

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

§ Always pull with rebase

git config --global pull.rebase true

§ Colorful CLI

To have colored output when doing git status and git diff:

git config --global color.ui "auto"

§ CPU threads

To enable automatic detection of CPU threads to use for packing repositories:

git config --global pack.threads "0"

§ Useful alias

Add this to your ~/.gitconfig:

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

  ll = log --graph --abbrev-commit --decorate \
  --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ai)%C(reset) \
  %C(white)%s%C(reset) %C(dim red)- %an%C(reset)%C(bold yellow)%d%C(reset)'

  lll = log --graph --abbrev-commit --decorate \
  --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
  %C(white)%s%C(reset) %C(dim red)- %an%C(reset)%C(bold yellow)%d%C(reset)' \
  --branches

  co = checkout
  ci = commit
  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

[credential]
  helper = cache

[diff]
  algorithm = histogram

§ Global .gitignore

Let’s define a global .gitignore file:

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

And let’s use it to ignore Visual Studio Code project files and also files generated by the ElixirLS plugin:

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

§ Dealing with line endings

Linux / Mac

If you are a Linux / Mac user:

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

Windows

If you are a Windows user:

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

§ Links

§ Basics

§ Advanced use cases

§ Hosted services

FINIS
Got comments or feedback?
Follow me on twitter
v1.1.25