Skip to content

Instantly share code, notes, and snippets.

Last active April 17, 2024 10:04
Show Gist options
  • Save tdd/470582 to your computer and use it in GitHub Desktop.
Save tdd/470582 to your computer and use it in GitHub Desktop.
Nice, useful global Git configuration
# Put this in your ~/.gitconfig or ~/.config/git/config
# Windows users: "~" is your profile's home directory, e.g. C:\Users\<YourName>
name = Your Full Name
email = your@email.tld
# Enable colors in color-supporting terminals
ui = auto
# List available aliases
aliases = !git config --get-regexp alias | sed -re 's/alias\\.(\\S*)\\s(.*)$/\\1 = \\2/g'
# Command shortcuts
ci = commit
co = checkout
st = status
# Display tree-like log, because default log is a pain…
lg = log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'
# Useful when you have to update your last commit
# with staged files without editing the commit message.
oops = commit --amend --no-edit
# Ensure that force-pushing won't lose someone else's work (only mine).
push-with-lease = push --force-with-lease
# Rebase won’t trigger hooks on each "replayed" commit.
# This is an ugly hack that will replay each commit during rebase with the
# standard `commit` command which will trigger hooks.
rebase-with-hooks = rebase -x 'git reset --soft HEAD~1 && git commit -C HEAD@{1}'
# List local commits that were not pushed to remote repository
review-local = "!git lg @{push}.."
# Edit last commit message
reword = commit --amend
# Undo last commit but keep changed files in stage
uncommit = reset --soft HEAD~1
# Remove file(s) from Git but not from disk
untrack = rm --cache --
# Don't paginate output by default
pager = cat
# Global ignore file (not shared)
excludesfile = ~/.gitignore_global
# Global shared hooks directory
# hooksPath = ~/.githooks
# Out of luck: on Windows w/o msysGit? You may have Notepad++…
# editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
# If you want to use Sublime Text 2's subl wrapper:
# editor = subl -w
# Sublime Text 3 on Windows:
# editor = 'c:/Program Files/Sublime Text 3/subl.exe' -w
# VSCode
editor = code --wait
# Don't consider trailing space change as a cause for merge conflicts
whitespace = -trailing-space
# Use better, descriptive initials (c, i, w) instead of a/b.
mnemonicPrefix = true
# Show renames/moves as such
renames = true
# When using --word-diff, assume --word-diff-regex=.
wordRegex = .
# Display submodule-related information (commit listings)
submodule = log
# Use VSCode as default diff tool when running `git diff-tool`
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
# Auto-fetch submodule changes (sadly, won't auto-update)
recurseSubmodules = on-demand
break = true
heading = true
lineNumber = true
# Consider most regexes to be ERE
extendedRegexp = true
# Use abbrev SHAs whenever possible/relevant instead of full 40 chars
abbrevCommit = true
# Automatically --follow when given a single path
follow = true
# Disable decorate for reflog
# (because there is no dedicated `reflog` section available)
decorate = false
# Display common-ancestor blocks in conflict hunks
# conflictStyle = diff3
# Disable fast-forward merges as default merge strategy.
# Force explicit call of `git merge --ff …`.
ff = false
# Custom/dedicated merge drive for npm lock files (`package-lock.json`).
# Also works with Yarn.
# Use Git attributes to set targeted files (located at `~/.config/git/attributes``
# when installed with npm).
# See
# [merge "npm-merge-driver"]
# name = automatically merge npm lockfiles
# driver = npx npm-merge-driver merge %A %O %B %P
# Clean up backup files created by merge tools on tool exit
keepBackup = false
# Clean up temp files created by merge tools on tool exit
keepTemporaries = false
# Put the temp files in a dedicated dir anyway
writeToTemp = true
# Auto-accept file prompts when launching merge tools
prompt = false
# [page]
# Use custom pager to get an better log on terminal.
# As this is an external tool it has to be installed.
# See
# show = diff-so-fancy | less --tabs=4 -RFX
# This is GREAT… when you know what you're doing and are careful
# not to pull --no-rebase over a local line containing a true merge.
# rebase = true
# This option, which does away with the one gotcha of
# auto-rebasing on pulls, is only available from 1.8.5 onwards.
# rebase = preserve
# WARNING! This option, which is the latest variation, is only
# available from 2.18 onwards.
rebase = merges
# Default push should only push the current branch to its push target, regardless of its remote name
default = upstream
# When pushing, also push tags whose commit-ishs are now reachable upstream
followTags = true
# [rebase]
# Rebase advanced usage.
# Automagically reorder and prefix your commands while doing an interactive
# rebase. This has to be used with `--fixup` and/or `--squash` options for
# `git commit`.
# autoSquash = true
# Automatically stash current WD and stage when running rebase
# then you won't have to manually `git stash push` and `git stash pop`
# after and before your rebase.
# autoStash = true
# [rerere]
# If, like me, you like rerere, uncomment these
# autoupdate = true
# enabled = true
# Display submodule rev change summaries in status
submoduleSummary = true
# Recursively traverse untracked directories to display all contents
showUntrackedFiles = all
[color "branch"]
# Blue on black is hard to read in git branch -vv: use cyan instead
upstream = cyan
# Sort tags as version numbers whenever applicable, so 1.10.2 is AFTER 1.2.0.
sort = version:refname
prereleaseSuffix = -pre
prereleaseSuffix = .pre
prereleaseSuffix = -beta
prereleaseSuffix = .beta
prereleaseSuffix = -rc
prereleaseSuffix = .rc
Copy link

tdd commented Apr 3, 2013

Bonjour Charles,

(désolé pour le lag, je n'avais apparemment pas été notifié par e-mail de ton commentaire)

Pas exactement… Git ne retire pas ces trucs-là pour toi via cette option : il faudrait un filtre textuel. C'est généralement plutôt le boulot, en amont, de ton éditeur (tous les éditeurs valables savent le faire).

L'option core.whitespace liste les « problèmes » d'espacement à considérer/signaler lors d'un git diff (et par extension un git add -p) ou d'un git apply --whitespace=errors, et à tenter de corriger lors d'un git apply ou git rebase en --whitespace=fix.

La valeur trailing-space est un raccourci pour blank-at-eol,blank-at-eof, qui cible donc les espacements en fin de ligne et les lignes en fin de fichier (ce dernier souci est très courant). Indiquée ici en négatif (-trailing-space), elle désactive ces détections / ne considère pas ces aspects comme problématiques.

Copy link

K4nz4ki commented Oct 1, 2015

Un grand merci pour la config

Copy link

tdd commented Nov 26, 2015

Just added the %ad variant in git lg, defaulting to --date=relative, to let you override the date format in git lg using --date=…. Neat trick by Erwann Leblanc 🎉

Copy link

NerOcrO commented Jun 22, 2016

Merci pour ces précieuses informations !
L'option pull.rebase est presque géniale ; elle ne me montre plus ce que je pull, y a t il moyen de revoir tout ça ?

Copy link

tdd commented Jul 14, 2016

Heeeeu en fait pull.rebase ne change rien au fonctionnement du fetch, c'est après que ça change (rebase au lieu de merge). Du coup si tu ne vois rien avant la partie rebase, c'est qu'en fait tu étais, sur ton essai, à jour côté fetch.

Copy link

tdd commented Mar 5, 2019

Dernière mise à jour à l'instant, suite aux suggestions de @mbrehin

Copy link

rs459 commented Mar 5, 2019

@tdd les suggestions de @mbrehin sont visibles quelque part ? (Pour comprendre les différences)

Copy link

rs459 commented Mar 8, 2019

@tdd les suggestions de @mbrehin sont visibles quelque part ? (Pour comprendre les différences)

Autant pour moi, j’avais suivi un lien ou j’avais pas l’historique du Gist.

Copy link

bgondy commented Mar 22, 2019

@tdd Un avis sur l'utilisation de pager = less -FX comme proposé ici ?

Copy link

mbrehin commented Jun 12, 2019

@bgondy on utilise diff-so-fancy même si ça n’est pas retranscrit ici (on ne veut pas forcer la main et imposer un outil externe aux gens qui souhaitent récupérer cette conf).

En pratique notre conf contient ça : pager = diff-so-fancy | less --tabs=4 -RFX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment