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
You can check it's working with this:
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:
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 generatedby 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
- Got 15 minutes and want to learn Git?
- A Guided Tour through the Fundamentals of Git (tutorial)
- Pro Git by Scott Chacon (libro)
- A visual Git reference
- Git Quick Reference
- Git for everyone
Advanced use cases
- How to setup your own private Git repositories with Gitolite
- How to setup automatic Hugo website generation and deployment with Git
Top comments (0)