-
Notifications
You must be signed in to change notification settings - Fork 0
gitconfig
The .gitconfig
files provide options in order to configure the git
toolchain and workflows.
There are three ways of how to set git
configurations. See it as different scopes. Types are:
- System config (
--system
); applies to entire machine and all users) - User config (
--global
) - Repo-specific config (in local repo (in
.git/config
))
There are some default locations but the easiest way ist to use git config --list --show-origin
(all files named .gitconfig
are of our interest).
Example of adding Notepad++ as editor in Windows:
[core]
# Pay attention on quoting!
editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
# or
editor = "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession"
# or also
editor = 'vim'
# or for sublime
editor = 'subl'
Path names are restricted to a certain length (4096 Bytes
by git
; 260 Bytes
by the Windows restriction). Therefore you can set the longpath
option:
[core]
longpaths = true
[user]
name = Master Git
email = [email protected]
# Use a proxy
[http]
proxy = http://bestboy:@192.0.2.150:3128
[https]
proxy = http://bestboy:@192.0.2.150:3128
# Don't use a proxy for these URLs
[http "http://some.url.com"]
proxy = ""
[https "https://some.url.com"]
proxy = ""
[commit]
gpgsign = true # To sign all commits by default in any local repository on your computer
[user]
# Generate key: gpg --full-generate-key
# Show keys: gpg --list-secret-keys --keyid-format=long
# pub rsa4096/<someHash> 2020-12-12 [SC]
#
# Add key (-> <someHash>) to .gitconfig manually or via: git config --global user.signingkey <Key>
signingkey = 55555F4C861DA238
# Export format for GitHub: gpg --armor --export <someHash>
Check if commit is signed: git verify-commit <commitID>
[credential]
helper = cache --timeout=3600
# Example for Windows
[merge]
tool = kdiff3
guitool = kdiff3
[mergetool "kdiff3"]
path = "/c/Program Files/KDiff3/kdiff3.exe"
[diff]
tool = kdiff3
guitool = kdiff3
path = "/c/Program Files/KDiff3/kdiff3.exe"
Note: overwriting an existing (build-in) command via an alias is not possible and will be ignored
[alias]
log = log -p # NOT possible since `log` is a built-in command -> git ignores this
lg = log -p # This is fine
cmt = commit --signoff # Also fine
You can define references to multiple git configs based on repository locations:
# Check config (in repo dir) with: $ git config --show-origin --get user.email
# Example for Windows
# `gitdir` paths are Windows paths (not git bash paths)
# The slashes (`/`) in the `gitdir` paths are important!
[includeIf "gitdir:C:/work-repos/"]
path = ~/.gitconfig-priv # Path to the git config
[includeIf "gitdir:C:/priv-repos/exception/"]
path = ~/.gitconfig-work
[includeIf "gitdir:C:/priv-repos/"]
path = ~/.gitconfig-work
# Generic options for all configs:
[credential]
helper = cache --timeout=3600
# ...
git config --list --show-origin
to find out the git config location and the corresponding options.
cd
into a repository and execute to see repo-specific options.
Add in your sub-.gitconfig
:
[core]
sshCommand = "ssh -i ~/.ssh/private_rsa_key"
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License *.
Code (snippets) are licensed under a MIT License *.
* Unless stated otherwise