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

View file

@ -5,3 +5,105 @@
# Manage the bare `git` repository in ~/ holding the dotfiles
alias dotfiles='git --git-dir=$XDG_DATA_HOME/dotfiles --work-tree=$HOME'
# Integrate `git`
if _command_exists git; then
# Check if a "main" branch exists in place of a "master" branch
git_main_branch() {
if [ -n "$(git branch --list main)" ]; then
echo "main"
else
echo "master"
fi
}
alias g='git'
alias ga='git add'
alias gap='git add --patch'
alias gbr='git branch'
alias gbra='git branch --all'
alias gbrd='git branch --delete'
alias gbrdd='git branch --delete --force'
alias gbrm='git branch --move'
alias gci='git commit'
alias gcim='git commit --message'
alias gcl='git clone'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcod='git checkout develop'
alias gcom='git checkout $(git_main_branch)'
alias gcp='git cherry-pick'
alias gdf='git diff-minimal'
alias gdlc='git diff-last-commit'
alias gds='git diff-staged'
alias gfe='git fetch'
alias ghi='git history'
alias ghia='git history --all'
alias glc='git last-commit'
alias glg='git log'
alias glga='git log --all'
alias gme='git merge'
alias gmea='git merge --abort'
alias gmec='git merge --continue'
alias gmeff='git merge --ff-only'
alias gmenoff='git merge --no-ff'
alias gol='git oneline'
alias gola='git oneline --all'
alias gpl='git pull'
alias gplrb='git pull --rebase'
alias gps='git push'
alias gpsf='git push --force'
alias grb='git rebase --committer-date-is-author-date'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbi='git rebase --interactive'
alias grbq='git rebase --quit'
alias grbs='git rebase --skip'
alias grepc='git grep-code'
alias grepl='git grep-log'
alias grept='git grep-text'
alias grl='git reflog'
alias grm='git rm'
alias grs='git reset'
alias grv='git revert'
alias gs='git status'
alias gss='git status --short'
alias gsh='git show'
alias gst='git stash'
alias gsta='git stash push --include-untracked'
alias gstam='git stash push --include-untracked --message'
alias gstapp='git stash apply'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gstsh='git stash show'
alias gsu='git summary'
alias gsua='git summary --all'
fi