DEV Community

Cover image for Basic Git configuration
Víctor Adrián
Víctor Adrián

Posted on • Originally published at lobotuerto.com on

Basic Git configuration


You can check the latest updated version of this article at lobotuerto's notes - Basic Git configuration.


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
Enter fullscreen mode Exit fullscreen mode

You can check it's working with this:

git --version
# git version 2.17.1
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Colorful CLI

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

git config --global color.ui "auto"
Enter fullscreen mode Exit fullscreen mode

CPU threads

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

git config --global pack.threads "0"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Global .gitignore

Let’s define a global .gitignore file:

git config --global core.excludesfile ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode

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

echo ".vscode/" >> ~/.gitignore_global
echo ".elixir_ls/" >> ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Windows

If you are a Windows user:

git config --global core.autocrlf true
git config --global core.safecrlf true
Enter fullscreen mode Exit fullscreen mode

Links

Basics

Advanced use cases

Hosted services

Oldest comments (0)