Last active
July 4, 2016 14:27
-
-
Save marek-saji/d790b3274984e38111a8 to your computer and use it in GitHub Desktop.
Useful things to put in your ~/.gitconfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
email = [email protected] | |
name = Your Name | |
[github] | |
user = your-login | |
[color] | |
ui = auto | |
[diff] | |
# Show submodule commits instead of hashes | |
submodule = log | |
[pull] | |
# Normally git-pull merges fetched branch into current branch, this | |
# switches this behaviour to rebase | |
# This makes commit history more linear | |
rebase = true | |
[fetch] | |
# Remove deleted remote branches | |
prune = true | |
[push] | |
default = tracking | |
# Do not allow pushing submodule revisions that are not available in | |
# remote-tracking branch. | |
recurseSubmodules = check | |
[status] | |
# Show submodule commits | |
submoduleSummary = -1 | |
[grep] | |
lineNumber = true | |
[alias] | |
# common typos | |
vomit = commit | |
stauts = status | |
staus = status | |
ad = add | |
# Short and sweet, with just enough information | |
ls = status -su | |
# TODO cut at max($COLUMNS, first occurance of "]") | |
b = !"git -c color.ui=always branch -vv | sed -s 's/\\].*$/]/' | less -SRX --quit-if-one-screen" | |
pullpush = !git pull && git push | |
stashpull = !"command git stash save 'STASHED FOR PULLING' && git pull && git stash pop #" | |
# branches by last commit date | |
# source: https://davidwalsh.name/sort-git-branches | |
activebranches = !"git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)' refs/heads | sed -e 's~refs/heads/~~'" | |
pullall = !git submodule update --remote --rebase && git pull | |
all = !"\"$@\" ; command git submodule foreach --recursive \"$@\" | sed -r -e \"s/^Entering '(.*)'$/[30;46mEntering '\\1'[m/\" #" | |
gitall = !"command git all git -c color.ui=always" | |
diffall = !"git gitall diff \"$@\" | command git pager #" | |
grepall = "gitall grep" | |
statusall = "gitall status" | |
# checkoutall = "gitall checkout" | |
# stashall = "gitall stash" | |
backup = !"set -e ; TARGET=\"/tmp/git$( echo $PWD | sed -e 's/\\//:/g' )\" ; echo \"Backing up to $TARGET\" ; { [ -e \"$TARGET\" && trash \"$TARGET\" ; } ; cp -ra .git \"${TARGET}\"" | |
cprev = !git rev-parse HEAD | tee /dev/stderr | xclip -in -selection clipboard | |
# open | |
open = !"command git web--browse $( printf \"$( command git config --get project.commit-url )\" \"$( command git rev-parse \"${1:-HEAD}\" )\" ) #" | |
# slim log | |
lg = log --graph --pretty=slim --abbrev-commit --date=relative --submodule=log | |
# lg date: sorted by date and with absolute dates | |
lgd = log --graph --pretty=slim --abbrev-commit --date=local --date-order --submodule=log | |
# lg upstream: also show upstream branch | |
lgu = !command git lg $( command git rev-parse --symbolic HEAD@{u} || echo master ) HEAD | |
# lg others: not my commits | |
lgo = log --graph --pretty=slim --abbrev-commit --date=relative --author='^(?!Marek.*Augustynowicz).*$' --perl-regexp --submodule=log | |
# lg date, upstream | |
lgdu = !command git lgd $( command git rev-parse --symbolic HEAD@{u} || echo master ) HEAD | |
# lg me: my commits from all branches, by date | |
lgme = !command git lgd --author=\"$( command git config --get user.name )\" --all | |
# branches hierarchy | |
lgb = !command git lga --simplify-by-decoration | |
# show commits from all branches | |
lga = !command git lgd --all | |
# show all commits that exist | |
#lgaa = !command git lg $( find "$( git rev-parse --show-toplevel )"/.git/objects/?? -type f | grep -Eo '[a-f0-9]{2}/[a-f0-9]{38}' | tr -d / ) | |
# show all commits from reflog | |
lgaa = !command git lgd $( command git reflog --format=%H ) | |
# show all commits that are unreachable | |
lgaaa =!command git fsck --unreachable | grep commit | cut -d\\ -f3 | xargs git lgd --all | |
# show commits from submodules as well | |
# (Skips first commit, because it may be too big to handle) | |
#lgs = !command git -c color.ui=no log --graph --oneline -U0 --submodule $( command git log --format=format:%H --reverse --ancestry-path $( command git rev-list --max-parents=0 HEAD ).. | head -n1 ).. | grep -E '^[*| /\\]+([0-9a-f]{7} |Submodule |> |$)' | eval "$( command git config --get core.pager )" | |
lgs = "!command git -c color.ui=always lg -U0 -p --submodule $( command git log --format=format:%H --reverse --ancestry-path $( command git rev-list --max-parents=0 HEAD ).. | head -n1 ).. | grep -vE \"^((\\[[0-9;]*m)*[| ])+(\\[[0-9;]*m)* ($|(\\[[0-9;]*m)*(diff|index|new|Binary|rename|similarity|deleted|[\\@+-]))\" | command git pager #" | |
# code review | |
review = "!START=\"$1\"; test \"$#\" -gt 0 && shift; git log --reverse -p $( { test -n \"$START\" && echo \"$START\"; } || git config --get project.main-branch 2>/dev/null || echo master )@{u}.." | |
# what's new since last (version?) tag | |
whatsnew = "!command git fetch --tags && { LAST=\"$( command git describe --tags --abbrev=0 --match='v*' 2>/dev/null || command git describe --tags --abbrev=0 )\" ; command git log --reverse --first-parent \"${LAST}\"..master \"${LAST}\"..master@{u}; }" | |
# grep with some context (and a header) | |
hgrep = grep --heading --show-function -B3 -A3 | |
# diff by word | |
diffword = diff --word-diff --word-diff-regex='\\w+|[[:space:]]+|[^[:space:]]' | |
# diff by character | |
diffchar = diff --word-diff --word-diff-regex='.' | |
# checkout files with only whitespace changes | |
whitespacecheckout = "!command git status --porcelain | GREP_OPTIONS= grep '^.M' | cut -b4- | while read file ; do if test -z \"$( command git diff -w \"$file\" )\"; then command git checkout -- \"$file\" ; fi; done" | |
rebaselocal = "!REMOTE=$( command git rev-parse --abbrev-ref HEAD@{u} || git config --get project.main-branch 2>/dev/null || echo master ) ; command git rebase -i \"$@\" $( command git merge-base HEAD ${REMOTE} ) #" | |
rebasebranch = "!REMOTE=$( git config --get project.main-branch 2>/dev/null || echo master ) ; if [ \"${REMOTE}\" = \"$( command git rev-parse --abbrev-ref HEAD )\" ]; then git rebaselocal \"$@\"; else command git rebase -i \"$@\" $( command git merge-base HEAD ${REMOTE} ); fi #" | |
# Used by other aliases | |
pager = !"eval \"$( command git config --get core.pager || which sensible-pager || echo ${PAGER:-less} )\"" | |
[pretty] | |
slim = "%C(red)%h%C(yellow)%d%C(reset) %s %C(green)(%cd) %C(bold blue)<%an>%C(reset)" | |
worklog = "%C(yellow)%ai %C(red)%h%C(yellow)%d%C(reset)%n%B" | |
worklogdates = "%n%C(yellow)%ai %C(red)%h%C(yellow)%d%C(reset)" | |
[web] | |
browser = xdg-open | |
[browser "xdg-open"] | |
cmd = xdg-open | |
[core] | |
# pager | |
# - use n/p in git-diff (and friends) to cycle through commit, diff and diff chunks | |
# - replace emoji codes with emojis, where possible | |
# These do not work: | |
# -e 's/:heavy_minus_sign:/➖/g' -e 's/:heavy_plus_sign:/➕/g' -e 's/:bug:/🐛/g' | |
pager = "{ head -n-2 ~/.lesshst ; printf \".less-history-file:\n.search\n\\\"^(commit|diff|@@)\n\\\"^(commit|diff)\n\\\"^commit\n\" ; tail -n2 ~/.lesshst ; } > ~/.gitlesshst ; { [ -e /usr/share/doc/git/contrib/diff-highlight/diff-highlight ] && perl /usr/share/doc/git/contrib/diff-highlight/diff-highlight || cat; } | sed -e 's/:arrow_up:/⬆/g' -e 's/:arrow_down:/⬇/g' -e 's/:arrows_clockwise:/⭮/g' -e 's/:arrows_counterclockwise:/⭯/g' -e 's/:telephone:/☎/' -e 's/:sparke:/❇/g' -e 's/:zap:/⚡/g' -e 's/:heavy_minus_sign:/(-)/g' -e 's/:heavy_plus_sign:/(+)/g' -e 's/:bug:/(bug)/g' | less -MFRSX" | |
attributesfile = ~/.gitattributes | |
[diff] | |
renames = true | |
[diff "po"] | |
textconv = msgcat --no-location --no-wrap --sort-output | |
[diff "strings"] | |
textconv = strings | |
[diff "image"] | |
textconv = "exiftool \"$1\" | grep -vP '^(Directory|File (Name|Permissions|.*Date/Time))' ; convert \"$1\" jpg:- | jp2a --width=`tput cols` --colors - #" | |
[help] | |
# autocorrect = 30 | |
# vim: expandtab shiftwidth=4 tabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment