Basic Git configuration

Published on 2018/06/10 ‚óŹ Last updated on 2018/07

Table of contents

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.18.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"

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 --date=relative \
    --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
    %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'

    lll = log --graph --abbrev-commit --decorate --date=relative \
    --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
    %C(white)%s%C(reset) %C(dim white)- %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 = patience

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


— lt

Feedback & comments

Get in touch on Twitter

Or by good ol' email at adriandcs@gmail.com