1
0
Fork 0

Add configuration for git

- Add .config/git/config
  + Define aliases
  + Configure default behavior in various situations
  + Add user information with signing key
- Add .config/git/commit_msg_template.txt
- Add .config/git/ignore
- Integrate `git` aliases into the shell
This commit is contained in:
Alexander Hess 2026-06-11 18:32:27 +02:00
commit 5a40cb969f
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
5 changed files with 319 additions and 63 deletions

View file

@ -0,0 +1,17 @@
# SUBJECT -> What does the commit do?
# - Imperative mood, no "." at the end
# - Start with "Add", "Fix", "Make", "Remove", ...
#---------- 50 characters / 1 line ---------------|
# BODY -> The why and how
# - Use plain text without formatting
# + Use "-" and "+" as bullets
# - "See: URL" to link to external resources
#---------- 72 characters / multiple lines -----------------------------|
# ISSUE TRACKER -> Uncomment one of the lines below
# Closes #41
# Fixes #42
# Resolves #43

194
.config/git/config Normal file
View file

@ -0,0 +1,194 @@
[alias]
# ~/.config/shell/aliases contains short `git` aliases,
# for example, `gap` for `git add --patch`
# Synonyms as "specified" in the `git status` header
discard = checkout --
unstage = reset HEAD --
amend-commit = !git log -n 1 --pretty=tformat:%B | git commit -F - --amend # Keep the commit message
current-branch = !git rev-parse --abbrev-ref HEAD
project-root = rev-parse --show-toplevel
uncommit = reset --soft HEAD~1
# Sync the working directory into the index
sync-deleted = !git ls-files -z --deleted | xargs -r -0 git rm
sync = !git sync-deleted && git add . --all
# Make minimal diff the default
diff-minimal = diff --color-words=. --ws-error-highlight=all
diff-last-commit = diff --color-words=. --ws-error-highlight=all HEAD
diff-staged = diff --color-words=. --ws-error-highlight=all --staged
# Clean the project folder with intuitive commands
clean-all = !git reset --hard && git clean-ignored && git clean-untracked
clean-ignored = "!f() { if [ -f .python-version ]; then mv .python-version .python-version.XYZ; fi; if [ -f .env ]; then mv .env .env.XYZ; fi; git clean -X -d -f "$@"; if [ -f .python-version.XYZ ]; then mv .python-version.XYZ .python-version; fi; if [ -f .env.XYZ ]; then mv .env.XYZ .env; fi }; f"
clean-untracked = !git clean -x -d -e ".python-version" -e ".env" -f # because the "-e" flag does not work with "-X"
# Delete EVERYTHING not reachable from a branch from the repository
gc-everything = "!f() { git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc "$@"; }; f"
# Make the logs look nice by default
log-format1 = log --pretty='%C(auto)%h: %s%d%Creset%n%C(dim)%an @ %ad => %ar%n' --date=format:'%a %Y-%m-%d %H:%M:%S %z'
log-format2 = log --pretty='%C(auto)%h: %s%d%Creset%n%C(dim)%aN @ %ad => %ar%n%+b' --date=format:'%a %Y-%m-%d %H:%M:%S %z'
last-commit = !git log-format2 -1 -p --stat
history = !git log-format2 --graph
summary = !git log-format1 --graph
oneline = log --pretty='%C(auto)%h: %s%d' --graph
# Search the repository
grep-code = grep --break --context 1 --full-name --heading --line-number --show-function
grep-log = log --all --regexp-ignore-case --pretty='%C(auto)%h: %s%+D%Creset%n%C(reverse)%C(dim)%aN @ %ad = %ar%Creset%n%+b' --date=format:'%a %Y-%m-%d %H:%M:%S' --grep
grep-text = grep --break --context 1 --full-name --heading --ignore-case --line-number
# Prune local branches that were deleted remotely
prune-delete = "!git fetch --prune && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d"
prune-show = "!git fetch --prune && git branch -vv | grep ': gone]' | awk '{print $1}'"
aliases = config --get-regexp 'alias.*'
aliases-internal = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1/' | sort # used in ~/.config/shell/aliases
[clean]
requireforce = true
[color "branch"]
current = cyan dim bold reverse
local = green bold
remote = red bold
[color "decorate"]
HEAD = cyan dim bold reverse
branch = green bold
remoteBranch = red bold
stash = magenta dim bold reverse
tag = magenta bold
[color "diff"]
context = white
frag = blue dim bold reverse
meta = yellow dim bold reverse
new = green bold
old = red bold
whitespace = red dim bold reverse
[color "grep"]
context = white
filename = yellow dim bold reverse
function = white bold
linenumber = blue dim bold reverse
match = red bold
selected = white
separator = blue dim bold reverse
[color "interactive"]
error = red dim bold reverse
header = white
help = yellow bold
prompt = white dim bold reverse
[color "status"]
added = green bold
branch = cyan dim bold reverse
changed = yellow bold
header = white
localBranch = green bold
nobranch = red dim bold reverse
remoteBranch = red bold
unmerged = yellow dim bold reverse
untracked = red bold
[commit]
cleanup = strip
gpgSign = true
template = ~/.config/git/commit_msg_template.txt
verbose = true
[core]
editor = vim
excludesfile = ~/.config/git/ignore
pager = less --chop-long-lines --ignore-case --LONG-PROMPT --status-column --quit-if-one-screen
whitespace = -space-before-tab,tab-in-indent
[diff]
renames = true
submodule = log
[help]
autocorrect = 50
[init]
defaultBranch = main
[merge]
conflictstyle = diff3
ff = only
[pull]
ff = only
rebase = true
[push]
autoSetupRemote = true
default = upstream
recursesubmodules = check
[rerere]
enabled = true
[url "https://bitbucket.org/"]
insteadOf = bb:
[url "https://github.com/"]
insteadOf = gh:
[url "https://gitlab.com/"]
insteadOf = gl:
[user]
name = Alexander Hess
email = alexander@webartifex.biz
signingKey = alexander@webartifex.biz

6
.config/git/ignore Normal file
View file

@ -0,0 +1,6 @@
# Generic temporary files
*.backup
*.bak
*.orig
*.temp
*.tmp