Skip to content

Instantly share code, notes, and snippets.

@dnitros
Last active March 8, 2024 07:19
Show Gist options
  • Save dnitros/b38061d9084c290f47569007811aa190 to your computer and use it in GitHub Desktop.
Save dnitros/b38061d9084c290f47569007811aa190 to your computer and use it in GitHub Desktop.
Git configuration file `${HOME}/.gitconfig`
# file location: ${HOME}/.gitconfig
# Note:
# [Windows users] If you are on windows, please search for the word 'windows' - and fix those lines - they seem to cause some trouble
# [General] Since some of the settings are specific to my setup (ie presence of fles), I have marked those lines with comments 'Personal' - you can go ahead and change those to your equivalents or delete them altogether
# [General] Since I use 'diff-so-fancy' as the diffing tool, it's absence on your system will cause some errors. If you are able to, I would sincerely urge you to install and use it for a much better experience. If not, please replace all such occurrences back to use 'diff'
# Note: Even though this will show up twice in `git config -l` - it will still be overridden based on the order of the includeIf lines below
[includeIf "gitdir/i:~/"]
path = ~/.gitconfig.inc
[includeIf "gitdir/i:~/project/personal/"]
path = ~/.gitconfig-personal.inc
[includeIf "gitdir/i:~/project/work/"]
path = ~/.gitconfig-work.inc
[advice]
detachedHead = true
[alias]
#############
# show the biggest files in the disk (this is not technically specific to git-tracked files)
big = "!git rev-list --objects --all | grep \"$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -100 | awk '{print $1}')\""
# compress disk-space-usage by deleting dangling commits
# Note: Do not use '--all' switch for reflog expire - since that also destroys stashes
cc = "!echo \"Size before: $(du -sh .git | cut -f1)\"; git remote prune origin; git repack; git prune-packed; git reflog expire --all --expire=1.week.ago; git maintenance run --task=gc; echo \"Size after: $(du -sh .git | cut -f1)\";"
# find dangling commits
dangling = fsck --no-reflog
# delete all local branches which are not present on remote
dlb = "!git branch -vv | GREP_OPTIONS= grep ': gone]' | awk '{print $1}' | xargs -I {} git branch -D {}"
# edit global git configuration
ec = config --global -e
# find files/folders with the parameter as part of the name
fd = "!git ls-files | GREP_OPTIONS=\"--color=auto\" grep -i"
# used to trim the gh-pages branch to a single commit and also deleting historical commits beyond X days (number of days can be sent as an optional arg, defaults to 25)
ghpg-trim = "!r() { days=${1:-19}; echo \"Will clean beyond $days days\" && git checkout gh-pages && echo \"Size before: $(du -sh *reports)\" && DIRECTORIES=$(find *-reports -mindepth 1 -maxdepth 1 -type d); for dir in ${DIRECTORIES}; do SHA_FROM_DIR=\"$(basename $dir)\"; COMMIT_DATE_IN_MILLIS=$(git show -s --format=%ct $SHA_FROM_DIR 2> /dev/null || echo 5000000000); COMMIT_DATE_IN_DAYS=$(echo \"$COMMIT_DATE_IN_MILLIS / (1000 * 60 * 60 * 24)\" | bc -l); (( ${COMMIT_DATE_IN_DAYS%.*} > ${days%.*} )) && git rm -rf $dir; done; git commit -m \"Deleting reports older than $days days\" && echo $(git rev-parse HEAD) > .git/info/grafts && git config advice.graftFileDeprecated false && FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f -- --all; rm -f .git/info/grafts; echo \"Size after: $(du -sh *reports)\" done;}; r"
# check if the specified branch has had a commit in the past 100 days and if so, report
# old = "!sh -c '[[ \"`git log $0/$1 --since 100.days -1 | wc -l`\" -eq 0 ]] && echo \"Will need to delete $0/$1\" && git push $0 --delete $1'"
old = "!sh -c '[[ \"`git log $0/$1 --since 100.days -1 | wc -l`\" -eq 0 ]] && echo \"Will need to delete $0/$1\"'"
# if a local commit exists, then amend it, else create a new commit with the specified message
sci = "!sh -c 'git status | GREP_OPTIONS=\"--color=auto\" grep \"is ahead of\"; \
if [ $? -eq 0 ]; then \
echo \"Amending existing commit\"; \
git amq; \
else \
echo \"Creating new commit\"; \
echo $0; \
git ci \"$0\"; \
fi'"
# show all commits in the past week done by the specified author
standup = log --since 1.week.ago --author
what = show -s --pretty='tformat:%h (%s, %ad)' --date=short
# show commit info summary (count and name)
who = shortlog -s --
#############
a = add --all
ai = add -i
#############
ap = apply
as = apply --stat
ac = apply --check
#############
ama = am --abort
amr = am --resolved
ams = am --skip
#############
b = branch
ba = branch -a
bd = branch -d
bdd = branch -D
br = branch -r
bc = rev-parse --abbrev-ref HEAD
bu = !git rev-parse --abbrev-ref --symbolic-full-name "@{u}"
bs = !git-branch-status
#############
c = commit
ca = commit -a
cm = commit -m
cam = commit -am
cem = commit --allow-empty -m
cd = commit --amend
cad = commit -a --amend
ced = commit --allow-empty --amend
#############
cl = clone
cld = clone --depth 1
clg = !sh -c 'git clone git://github.com/$1 $(basename $1)' -
clgp = !sh -c 'git clone git@github.com:$1 $(basename $1)' -
clgu = !sh -c 'git clone git@github.com:$(git config --get user.username)/$1 $1' -
#############
cp = cherry-pick
cpa = cherry-pick --abort
cpc = cherry-pick --continue
#############
d = diff
dp = diff --patience
dc = diff --cached
dk = diff --check
dck = diff --cached --check
dt = difftool
dct = difftool --cached
#############
f = fetch
fo = fetch origin
fu = fetch upstream
#############
fp = format-patch
#############
fk = fsck
#############
g = grep -p
#############
l = log --oneline
lg = log --oneline --graph --decorate
#############
ls = ls-files
lsf = !git ls-files | grep -i
#############
m = merge
ma = merge --abort
mc = merge --continue
ms = merge --skip
#############
o = checkout
om = checkout master
ob = checkout -b
opr = !sh -c 'git fo pull/$1/head:pr-$1 && git o pr-$1'
#############
pr = prune -v
#############
ps = push
psf = push -f
psu = push -u
pst = push --tags
#############
pso = push origin
psao = push --all origin
psfo = push -f origin
psuo = push -u origin
#############
psom = push origin master
psaom = push --all origin master
psfom = push -f origin master
psuom = push -u origin master
psoc = !git push origin $(git bc)
psaoc = !git push --all origin $(git bc)
psfoc = !git push -f origin $(git bc)
psuoc = !git push -u origin $(git bc)
psdc = !git push origin :$(git bc)
#############
pl = pull
pb = pull --rebase
#############
plo = pull origin
pbo = pull --rebase origin
plom = pull origin master
ploc = !git pull origin $(git bc)
pbom = pull --rebase origin master
pboc = !git pull --rebase origin $(git bc)
#############
plu = pull upstream
plum = pull upstream master
pluc = !git pull upstream $(git bc)
pbum = pull --rebase upstream master
pbuc = !git pull --rebase upstream $(git bc)
#############
rb = rebase
rba = rebase --abort
rbc = rebase --continue
rbi = rebase --interactive
rbs = rebase --skip
#############
re = reset
rh = reset HEAD
reh = reset --hard
rem = reset --mixed
res = reset --soft
rehh = reset --hard HEAD
remh = reset --mixed HEAD
resh = reset --soft HEAD
rehom = reset --hard origin/master
#############
r = remote
ra = remote add
rr = remote rm
rv = remote -v
rn = remote rename
rp = remote prune
rs = remote show
rao = remote add origin
rau = remote add upstream
rro = remote remove origin
rru = remote remove upstream
rso = remote show origin
rsu = remote show upstream
rpo = remote prune origin
rpu = remote prune upstream
#############
rmf = rm -f
rmrf = rm -r -f
#############
s = status
sb = status -s -b
#############
sa = stash apply
sc = stash clear
sd = stash drop
sl = stash list
sp = stash pop
ss = stash save
ssk = stash save -k
sw = stash show
st = !git stash list | wc -l 2>/dev/null | grep -oEi '[0-9][0-9]*'
#############
t = tag
td = tag -d
#############
w = show
wp = show -p
wr = show -p --no-color
#############
svnr = svn rebase
svnd = svn dcommit
svnl = svn log --oneline --show-commit
#############
subadd = !sh -c 'git submodule add git://github.com/$1 $2/$(basename $1)' -
subrm = !sh -c 'git submodule deinit -f -- $1 && rm -rf .git/modules/$1 && git rm -f $1' -
subup = submodule update --init --recursive
subpull = !git submodule foreach git pull --tags -f origin master
#############
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
assumed = !git ls -v | grep ^h | cut -c 3-
unassumeall = !git assumed | xargs git unassume
assumeall = !git status -s | awk {'print $2'} | xargs git assume
#############
bump = !sh -c 'git commit -am \"Version bump v$1\" && git psuoc && git release $1' -
release = !sh -c 'git tag v$1 && git pst' -
unrelease = !sh -c 'git tag -d v$1 && git pso :v$1' -
merged = !sh -c 'git o master && git plom && git bd $1 && git rpo' -
aliases = !git config -l | grep alias | cut -c 7-
snap = !git stash save 'snapshot: $(date)' && git stash apply 'stash@{0}'
bare = !sh -c 'git symbolic-ref HEAD refs/heads/$1 && git rm --cached -r . && git clean -xfd' -
whois = !sh -c 'git log -i -1 --author=\"$1\" --pretty=\"format:%an <%ae>\"' -
serve = daemon --reuseaddr --verbose --base-path=. --export-all ./.git
#############
behind = !git rev-list --left-only --count $(git bu)...HEAD
ahead = !git rev-list --right-only --count $(git bu)...HEAD
#############
ours = "!f() { git checkout --ours $@ && git add $@; }; f"
theirs = "!f() { git checkout --theirs $@ && git add $@; }; f"
subrepo = !sh -c 'git filter-branch --prune-empty --subdirectory-filter $1 master' -
human = name-rev --name-only --refs=refs/heads/*
[branch]
autosetupmerge = true
autosetuprebase = always
[checkout]
defaultRemote = origin
[color]
ui = auto
interactive = auto
pager = true
[color "branch"]
current = yellow bold
local = green bold
remote = cyan bold
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
whitespace = red reverse
[color "status"]
added = green bold
changed = yellow bold
untracked = red bold
[core]
pager = diff-so-fancy | less --tabs=2 -RFX
# editor = code --wait
editor = vi
autocrlf = input
excludesFile = ~/.gitignore
commentChar = *
whitespace = fix
[diff]
compactionHeuristic = true
[diff-so-fancy]
markEmptyLines = false
[fetch]
prune = true
pruneTags = true
parallel = 0
showForcedUpdates = true
[filter "lfs"]
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
[gc]
pruneexpire = now
[grep]
extendedRegexp = true
lineNumber = true
fullName = true
[gui]
pruneduringfetch = true
matchtrackingbranch = true
warndetachedcommit = true
tabsize = 2
[help]
autocorrect = 1
[init]
defaultBranch = master
[interactive]
# diffFilter = diff-so-fancy --patch
[merge]
defaultToUpstream = true
ff = only
renamelimit = 15000
autoStash = true
[pack]
threads = 4
[pager]
# log = diff-so-fancy | less --tabs=1,5 -RFX
show = diff-so-fancy | less --tabs=1,5 -RFX # windows
# Note: The '--pattern' switch sets some pre-search terms, but also scrolls to fill the whole console for single line change - which I dont like.
diff = diff-so-fancy | less --tabs=1,5 -RFX # --pattern '^(Date|added|deleted|modified): ' # windows
[pull]
rebase = true
autoStash = true
[push]
default = tracking
followTags = true
[rebase]
autoStash = true
[rerere]
enabled = true
autoUpdate = true
[sequence]
editor = interactive-rebase-tool
[stash]
untracked = true
[status]
showUntrackedFiles = all
# Convert to 'true' in case you work with submodules - but, will have visible perf slowdown on windows
submodulesummary = false
[submodule]
fetchJobs = 4
[tag]
sort = version:refname
[transfer]
fsckobjects = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment