Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Last active December 15, 2023 17:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fprochazka/983217 to your computer and use it in GitHub Desktop.
Save fprochazka/983217 to your computer and use it in GitHub Desktop.
.gitconfig
[user]
name = Filip Procházka
email = filip@prochazka.su
signingkey = *PG KEY*
[init]
defaultBranch = master
[core]
whitespace = fix,-indent-with-non-tab,space-before-tab,trailing-space,cr-at-eol
autocrlf = input
filemode = false
excludesfile = ~/.gitignore_global
# editor = subl -n -w
editor = nano
attributesfile = ~/.gitattributes
pager = less
[pager]
log = diff-highlight | less
show = diff-highlight | less
diff = diff-highlight | less
branch = false
[branch]
autosetuprebase = always
[diff]
algorithm = histogram
mnemonicprefix = true
# indentHeuristic = true # default from 2.18m
compactionHeuristic = true
# https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-diffrenameLimit
renameLimit = 0 # unlimited
renames = copies
noprefix = true
context = 5
[push]
default = current
autoSetupRemote = true
[pull]
rebase = true
[fetch]
prune = true
[advice]
statusHints = false
pushNonFastForward = false
skippedCherryPicks = false
[pack]
writeReverseIndex = true
[remote]
pushdefault = origin
[interactive]
diffFilter = diff-highlight
[commit]
gpgsign = true
[status]
showStash = true
# renames = defaults to diff.renames
# renameLimit = defaults to diff.renameLimit
[sequence]
# https://github.com/MitMaro/git-interactive-rebase-tool
# editor = interactive-rebase-tool
# https://github.com/sjurba/rebase-editor
# editor = "rebase-editor -c -- "
[rebase]
missingCommitsCheck = warn
abbreviateCommands = true
autosquash = true
# https://github.blog/2022-10-03-highlights-from-git-2-38/#rebase-dependent-branches-with-update-refs
updateRefs = true
[merge]
ff = false
# renames = defaults to diff.renames
# renameLimit = defaults to diff.renameLimit
[credential]
helper = store
[help]
autoCorrect = prompt
[gui]
diffcontext = 8
[log]
decorate = true
date = iso
[pretty]
# custom-log-oneline = "format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset %C(magenta)(%G?: %GS)%Creset"
custom-log-oneline = "format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"
[alias]
co = checkout
cp = cherry-pick
st = status
ap = add -p
ci = commit
qci = commit
cia = commit --amend
rb = rebase
rbm = !git rbi "$(git get-main-branch)"
rbmi = !git rbim
rbi = rebase -i
rbim = !git rbi "$(git get-main-branch)"
rba = rebase --abort
rbc = rebase --continue
rbs = rebase --skip
br = branch -vv --sort=-committerdate
b = branch -vv --sort=-committerdate
d = diff
dc = diff --cached
dw = diff --word-diff
mb = merge --no-ff
ff = merge --ff-only
stage = add
unstage = reset HEAD --
f = fetch --all --prune
fpush = push --force-with-lease
l = log --graph --pretty=custom-log-oneline --abbrev-commit --date=relative
ls = "l --stat -m"
lp = "l -p"
lw = "l -p --color-words"
h = !git --no-pager log --abbrev-commit --pretty=oneline "$(git get-main-upstream-branch)..$(git get-current-branch)"
lb = !git l $(git-current-branch-name)
logb = !git log $(git-current-branch-name)
assume-unchanged = "update-index --assume-unchanged"
assume-changed = "update-index --no-assume-unchanged"
com = !git co "$(git get-main-branch)" && git pull origin && git cleanup
up = "!git stash && git fetch && git pull @{u}"
pu = !git up && git push @{u} "$(git get-main-branch)"
k = !gitk
start = !git init && git commit --allow-empty -m "Initial commit"
wip = !git add --all && git commit -m 'WIP [ci skip]'
unwip = reset HEAD~1
cif = !git commit --fixup=$(git-log-vgrep-most-recent-commit 'fixup!')
cifi = !git-commit-fixup-ask
slurp = !git restore --source=HEAD^ --staged . && git commit --amend --allow-empty --no-edit
find = !sh -c 'git ls-tree -r --name-only HEAD | grep --color $1' -
cf = show --pretty="format:" --name-only
permission-reset = "!git diff -p | grep -E '^(diff|old mode|new mode)' | sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' | git apply"
cleanup = !git fetch --all --prune && git branches-merged-drop && git branches-gone-drop
# list cleanly merged local branches
# filter out current branch and master, as we never want to delete them
branches-merged-list = !git branch --merged "$(git get-main-branch)" | grep -E -i -v '^\\s*(\\*|master|main|develop)'
branches-merged-drop = !echo "Removing cleanly merged branches." && git branches-merged-list | xargs -n 1 -r git branch -d
# list local branches
# filter out current branch and master, as we never want to delete them
# filter the lines to the 'gone' keyword at a specific place of the output
# cut only the first column (branch name)
branches-gone-list = !git branch -vv | grep -E -i -v '^\\s*(\\*|master|main|develop)' |grep ' gone] ' | awk '{ print $1 }'
branches-gone-drop = !echo "Removing gone branches." && git branches-gone-list | xargs -n 1 -r git branch -D
get-current-branch = !git-current-branch-name
get-main-branch = !git show-ref --quiet refs/heads/master && echo "master" || echo "main"
get-main-upstream-branch = !git show-ref --quiet "refs/heads/upstream/$(git get-main-branch)" && echo "upstream/$(git get-main-branch)" || echo "origin/$(git get-main-branch)"
[color]
branch = auto
diff = auto
status = auto
sh = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red
new = green
whitespace = red reverse
[color "status"]
added = green
changed = red
untracked = cyan
[color "sh"]
branch = yellow
[cola]
spellcheck = false
tabwidth = 4
[diff "lisp"]
xfuncname = "^(\\(.*)$"
# xfuncname = "^(\\((cl-)?def(un|macro|method).*)$"
[diff "rstats"]
xfuncname = "^([a-zA-z.]+ <- function.*)$"
[diff "texinfo"]
# from http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=.gitattributes;h=c3b2926c78c939d94358cc63d051a70d38cfea5d;hb=HEAD
xfuncname = "^@node[ \t][ \t]*\\([^,][^,]*\\)"
[diff "orgmode"]
xfuncname = "^(\\*+.*)$"
#[diff "css"]
# xfuncname = "^([a-zA-Z#.@][^\\}]*)$"
# xfuncname = "^(.*\\{)$"
[diff "rust"] # Thanks to csabahenk
xfuncname = "^[ \t]*(pub|)[ \t]*((fn|struct|enum|impl|trait|mod)[^;]*)$"
[diff "exif"]
binary = true
# sudo apt-get install libimage-exiftool-perl
textconv = exiftool
[diff "phpf"]
xfuncname = "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
[diff "pdf"]
binary = true
[url "git@github.com:"]
insteadOf = "gh:"
pushInsteadOf = "github:"
pushInsteadOf = "git://github.com/"
[url "git://github.com/"]
insteadOf = "github:"
[url "git@gist.github.com:"]
insteadOf = "gst:"
pushInsteadOf = "gist:"
pushInsteadOf = "git://gist.github.com/"
[url "git://gist.github.com/"]
insteadOf = "gist:"
[includeIf "gitdir:~/devel/projects/shipmonk/"]
path = /home/fprochazka/devel/projects/shipmonk/.gitconfig
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
#*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
#*.sql
#*.sqlite
# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
# IDE generated files #
#######################
.project
.idea
# Other #
#########
.svn
.buildpath
#!/usr/bin/env bash
if ! [ -d .git ]; then
echo "Not a git repository";
exit 1;
fi
if git diff --cached --quiet --exit-code; then
echo "Nothing to commit";
exit 1;
fi
relativeToHead=0;
for commitId in `git --no-pager log --format=%H "$(git get-main-branch)...HEAD"`; do
commitMessage=$(git --no-pager log --format=%B -n 1 $commitId)
if [[ ${commitMessage:0:7} == "fixup! " ]] || [[ ${commitMessage:0:8} == "squash! " ]]; then
((relativeToHead++));
continue;
fi
git --no-pager log --pretty="format:${relativeToHead}. %Cred%h%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --date=relative -n1 $commitId;
echo
for filename in `git --no-pager diff --cached --name-only;`; do
git --no-pager diff --stat=160 --color "$commitId" "$commitId^" -- "$filename" | head -n 1;
done
((relativeToHead++));
done
if [ "$relativeToHead" -eq 0 ]; then
echo "no commits in branch found using $(git get-main-branch)...HEAD range";
exit 1;
fi
((relativeToHead--))
echo;
read -p "Pick a commit [0..${relativeToHead}]: " targetCommit
if [ -z "${targetCommit##*[!0-9]*}" ]; then
echo "expected a number in range [0..${relativeToHead}]";
exit 2;
fi
if [ ! "$targetCommit" -ge 0 -o ! "$targetCommit" -le "$relativeToHead" ]; then
echo "expected a number in range [0..${relativeToHead}]";
exit 3;
fi
git commit --fixup "HEAD~$targetCommit"
#!/usr/bin/env bash
set -euo pipefail
if ! [ -d .git ]; then
echo "Not a git repository";
exit 1;
fi
## thx https://stackoverflow.com/a/59115583/602899
for location in rebase-merge rebase-apply; do
path=$(git rev-parse --git-path ${location})
if test -d ${path}; then
revision=$(<${path}/head-name)
echo ${revision##refs/heads/}
exit 0
fi
done
git rev-parse --abbrev-ref HEAD
#! /bin/bash
if (( $# < 1 )); then
echo >&2 "Usage: $0 pattern [<since>..<until>]"
exit 1
fi
pattern=$1
shift
git log --format=%H $@ |
grep -v -f <(git log --format=%H "--grep=$pattern" $@) |
git log -1 --format="%H" --stdin --no-walk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment