Git knows the following configurations locations:
/etc/gitconfig
Configuration per system, settings apply to all users and all repositories access from that system.~/.gitconfig
or ~/.config/git/config
Configuration per user, settings apply to all repositories access by that user.${repository}/.git/config
Configuration per repository, settings apply to anyone accessing that repository.Hint
If a configuration is made in two locations, the more specific one overwrites the less specific one.
Example
if user.name is set both in ~/.gitconfig
(global) and ${repository}/.git/config
(local), the one in ${repository}/.git/config
is being used.
Set your name and email:
git config --global user.name "John Doe"
git config --global user.email john.doe@example.org
If you have a PGP Key you can use it to sign tags and commits with:
git config --global user.signingkey KEY_ID
Enable colors in Git outputs (e.g. in git diff, git log, etc.):
git config --global color.ui true
Show commit decorations (e.g. in git log, git show, etc.):
git config --global log.decorate true
Highlight uneeded whitespaces:
git config --global core.whitespace blank-at-eol,space-before-tab,indent-with-non-tab,blank-at-eof
If you are annoyed by the full SHA hashes, you can let Git shorten them for you to the common 7-characters string:
git config --global log.abbrevCommit true
If you are a Git expert and are bored by the hints that Git gives you, you can disable them:
git config --global advice.statusHints false
Sometimes it is handy to see differences not line based but word based. The following aliases define word-based pendants to the default line-based ones:
git config --global alias.wdiff "diff --color-words"
git config --global alias.wlog "log --color-words"
git config --global alias.wshow "show --color-words"
Git can use abbreviation for URLs to clone from. Using the following snippet in your global configuration file:
[url "git@git.example.org:foo/bar/"]
insteadOf = foobar:
This allows you to use:
git clone foobar:baz.git
instead of:
git clone git@git.example.org:foo/bar/baz.git
Git can push multiple branches if none is specified. To push all branches that are known in origin, use:
git config --global push.default matching
If you like Git to not show relativ paths to files in git status you can use:
git config --global status.relativePaths false
With Git and bash-completion installed, the shell prompt can be configured to display status information such as the current branch and if/what has changed. Use the following code in /etc/profile.d/zzz-git-sh-prompt.sh
.
#!/bin/sh
if [ -z "$BASH" ] && [ "$BASH" = "/bin/sh" ]
then
exit 0
fi
if [ "$(id -u)" -eq 0 ]
then
exit 0
fi
if [ -e /usr/lib/git-core/git-sh-prompt ] && [ -e /etc/profile.d/bash_completion.sh ]
then
# See /usr/lib/git-core/git-sh-prompt for more information about git-prompt options
export GIT_PS1_SHOWCOLORHINTS="true"
export GIT_PS1_SHOWDIRTYSTATE="true"
export GIT_PS1_SHOWSTASHSTATE="true"
export GIT_PS1_SHOWUNTRACKEDFILES="true"
export GIT_PS1_SHOWUPSTREAM="verbose"
export GIT_PS1_DESCRIBE_STYLE="branch"
export PROMPT_COMMAND="__git_ps1 '' '\[\e[0m\]\u@\h:\w\\\$\[\e[0m\] '"
fi