Basic Git configuration
Tags: git, productivity, terminal, setup
Published: 2018-06-11 15:03:05

---
title: Basic Git configuration
published: true
tags: [git, productivity, terminal, setup]
canonical_url: https://lobotuerto.com/blog/basic-git-configuration/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/nd32ow8nwze0n98pf1r6.png
---

***

You can check the latest updated version of this article at [lobotuerto's notes - Basic Git configuration.](https://lobotuerto.com/blog/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:

```bash
sudo apt install git
```

You can check it's working with this:

```bash
git --version
# git version 2.17.1
```

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:

```bash
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`:

```bash
git config --global color.ui "auto"
```

## CPU threads

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

```bash
git config --global pack.threads "0"
```

## Useful alias

Add this to your `~/.gitconfig`:

```bash
[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:

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

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

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

## Dealing with line endings

### Linux / Mac

If you are a **Linux / Mac** user:

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

### Windows

If you are a **Windows** user:

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

# Links

## Basics

- [Got 15 minutes and want to learn Git?](https://try.github.com/)
- [A Guided Tour through the Fundamentals of Git (tutorial)](http://gitimmersion.com/)
- [Pro Git by Scott Chacon (libro)](https://git-scm.com/book)
- [A visual Git reference](https://marklodato.github.com/visual-git-guide/index-en.html)
- [Git Quick Reference](http://jonas.nitro.dk/git/quick-reference.html)
- [Git for everyone](http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html)

## Advanced use cases

- [How to setup your own private Git repositories with Gitolite](https://lobotuerto.com/blog/how-to-setup-your-own-private-git-repositories-with-gitolite/ "How to setup your own private Git repositories with Gitolite")
- [How to setup automatic Hugo website generation and deployment with Git](https://lobotuerto.com/blog/how-to-setup-automatic-hugo-website-generation-and-deployment-with-git/ "How to setup automatic Hugo website generation and deployment with Git")

## Hosted services

- [GitHub](https://github.com/)
- [gitolite](https://github.com/sitaramc/gitolite) (self-hosted)
- [Bitbucket](https://bitbucket.org/)
- [GitLab](https://about.gitlab.com/) (can be self-hosted)