Skip to content

Instantly share code, notes, and snippets.

@pdemanget
Last active July 21, 2023 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdemanget/7ee823677f393d3ff1816f1de21b05ed to your computer and use it in GitHub Desktop.
Save pdemanget/7ee823677f393d3ff1816f1de21b05ed to your computer and use it in GitHub Desktop.
My git aliases and configuration
# This is Git's per-user configuration file.
# [user]
# name =
# email =
# Windows specific uncomment this on windows
# [mergetool "kdiff3"]
# path = C:/Program Files/KDiff3/kdiff3.exe
# trustExitCode = false
#[difftool "kdiff3"]
# path = C:/Program Files/KDiff3/kdiff3.exe
# trustExitCode = false
# pdemanget std config
[branch]
autosetuprebase = always
[color]
ui = true
[core]
editor = vim
excludesfile = ~/.gitignore
attributesfile = ~/.gitattributes
[diff]
renameLimit = 999999
guitool = kdiff3
[diff "image"]
command = ~/bin/git-imgdiff
[gui]
encoding = utf-8
[merge]
renameLimit = 999999
tool = kdiff3
guitool = kdiff3
[push]
default = current
[rebase]
autoStash = true
[rerere]
enabled = true
[webui]
autoupdate = true
[alias]
aa = add -A
ale = config -e --global
amend = "!f(){ [ $(git log -1 --pretty='%P' \"${1:-HEAD}\" | wc -w) -lt 2 ] && git commit --amend --no-edit; }; f"
br = branch
bra = branch -a
brc = rev-parse --abbrev-ref HEAD
brd = branch -D
brl = "!f(){ git branch --list \"$1\"; }; f"
brrm = "!f(){ git branch --list \"$1\" | xargs -r git branch -d; }; f"
brrmf = "!f(){ git branch --list \"$1\" | xargs -r git branch -D; }; f"
c = commit -m
ca = commit --amend
camd = "!f(){ [ $(git log -1 --pretty='%P' \"${1:-HEAD}\" | wc -w) -eq 1 ] && git commit --amend --no-edit; }; f"
ci = commit
co = checkout
cob = checkout -b
cp = cherry-pick
current-branch = "!(git symbolic-ref --quiet HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) | sed -r 's|^refs/heads/||'"
dic = diff --cached
dirt = !git add -A && git commit -m 'Dirty commit'
example = "!f(){ echo \\'\"$1\"\\'; }; f"
example2 = "!f(){ echo git branch --list \"$1\"*; }; f"
force-mergetool = !git list-conflicts | xargs git mergetool
git = !git
glog = log --oneline --all --graph --decorate
gone = ! "git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" {print $1}' | xargs -r git branch -D"
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
k = !gitk
ka = !gitk --all
l = log --pretty=format:'%Cred%h%Creset %Cgreen(%ci)%Creset %s %C(blue)<%an>%C(yellow)%d%Creset'
l1h = log --pretty=format:'%h' -n1
lg = log --graph --pretty=format:'%Cred%h%Creset %Cgreen(%ci)%Creset %s %C(bold blue)<%an>%Creset%C(yellow)%d%Creset'
lga = log --graph --pretty=format:'%Cred%h%Creset %Cgreen(%ci)%Creset %s %C(bold blue)<%an>%Creset%C(yellow)%d%Creset' --all
lgs = log --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'
list-conflicts = !git ls-files -u | cut -f 2 | sort -u
ln = log --pretty=format:'%Cred%h%Creset %Cgreen(%ci)%Creset %s %C(blue)<%an>%C(yellow)%d%Creset' -n10
logfiles = log --name-only --oneline
lol = log --oneline --graph --decorate --tags --all
ls = log --pretty=format:'%Cred%h%Creset %Cgreen(%ci)%Creset %s %C(blue)<%an>%C(yellow)%d%Creset'
no-unch = update-index --no-assume-unchanged
orphan = git checkout --orphan
pru= remote prune origin
psup="!git push --set-upstream origin $(git current-branch)"
pud = fetch origin dev:dev
puf = push --force-with-lease
pum = fetch origin main:main
pumh = fetch https main:main
pun= push -u origin
pur = pull --rebase
pus = fetch origin master:master
rim = rebase -i main
rs = restore
serv = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
showf = show --pretty=format: --name-only
st = status
sw = switch
tagv = git tag -l --sort=-v:refname
unch = update-index --assume-unchanged
@pdemanget
Copy link
Author

This mys standard git configuration: copy in your ~/ directory (backup the old one).
On Windows, uncomment mergetool and diff tool to use kdiff3 (kdiff3 is to be installed separatly).

@pdemanget
Copy link
Author

worktree usage
git worktree add ../master master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment