Skip to content

Instantly share code, notes, and snippets.

@kosty
Created October 15, 2020 01:53
Show Gist options
  • Select an option

  • Save kosty/83bcc659e0b2b505057671bdac063afd to your computer and use it in GitHub Desktop.

Select an option

Save kosty/83bcc659e0b2b505057671bdac063afd to your computer and use it in GitHub Desktop.
A good-enough .gitconfig
[push]
default = current
[merge]
conflictstyle = diff3
######
# Some hints on using vimdiff
# Following three keys (two keystrokes) `Ctrl-w =` make all of the windows equal
# `Ctrl-w j` jumps to lower window, which is MERGED
# `:diffget RE` applies remote
# `:diffg BA` applies BASE
# `:diffg LO` applies LOCAL
# Also see https://gist.github.com/mattratleph/4026987
# https://stackoverflow.com/questions/1251681/git-mergetool-generates-unwanted-orig-files
#
tool = vimdiff
prompt = false
[color]
ui = true
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = green
changed = yellow
untracked = red
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[alias]
# a = add --all
ap = add --patch
ai = add --interactive
aa = "!f(){ PATTERN=$1; find . -name \"${PATTERN}\" -not -path \"*/build/*\" -exec git add -v {} +; }; f"
up = add -u
#############
bv = branch --verbose --verbose
bm = branch -u origin/master
rbs = "!f() { BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); git branch -u origin/master; git fetch; git rebase && git branch -u origin/${BRANCH_NAME}; }; f"
#############
refresh = remote update origin --prune
remotes = remote -v
#############
c = commit --verbose
cm = commit --verbose -m
ca = commit -a --verbose
cam = commit -a --verbose -m
amend = commit --amend --verbose
#############
pushhh = push --force
#############
cl = clean -nd
# Amend the currently staged files to the latest commit
# amend = commit --amend --reuse-message=HEAD
# cp = commit --patch
# ci = commit --interactive
#############
fp = format-patch
#############
m = checkout master
co = checkout
cob = checkout -b
# Switch to a branch, creating it if necessary
go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f"
# Swithc to a "feature", creating it if necessary
fe = "!f() { BRANCH_NAME=\"feature/$1-$USER\"; git checkout -b \"$BRANCH_NAME\" 2> /dev/null || git checkout \"$BRANCH_NAME\"; }; f"
sp = "!f() { BRANCH_NAME=\"scratchpad/$1-$USER\"; git stash; git checkout -b \"$BRANCH_NAME\" 2> /dev/null || git checkout \"$BRANCH_NAME\"; git stash pop; }; f"
issue = "!f() { BRANCH_NAME=\"issues/$1\"; git stash; git checkout -b \"$BRANCH_NAME\" 2> /dev/null || git checkout \"$BRANCH_NAME\"; git stash pop; }; f"
mt = "!f() { BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); git checkout -b feature/${BRANCH_NAME##*/}; }; f"
#############
# s = status
st = status
# View the current working tree status using the short format
s = status -s
#############
diffiles = diff --name-only
#############
ours = "!f() { git checkout --ours $@ && git add $@; }; f"
theirs = "!f() { git checkout --theirs $@ && git add $@; }; f"
#############
whois = "!sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
#############
# Hint: use `git lg -p` for verpose commit log
lg = log --pretty=oneline --abbrev-commit
hist = log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
# View abbreviated SHA, description, and history graph of the latest 20 commits
# l = log --pretty=oneline -n 20 --graph --abbrev-commit
# list branches sorted by last modified
b = branch
bra = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
# show files in a commit
showfiles = show --name-only --pretty=""
# list aliases
la = "!git config -l | grep alias | cut -c 7-"
undo-commit = reset --soft HEAD~1
# show origin url
o = config --get remote.origin.url
# Find branches containing commit
fb = "!f() { git branch -a --contains $1; }; f"
# Find tags containing commit
ft = "!f() { git describe --always --contains $1; }; f"
# Find commits by source code
fc = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short -S$1; }; f"
# Find commits by commit message
fm = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short --grep=$1; }; f"
root = "rev-parse --show-toplevel"
# IDE integration
ide = "!f() { for I in `git diff --name-only | grep $1`; do idea `pwd` $I; done; }; f"
# Untested but interesting
# clean-merged = !git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d
# Show the diff between the latest commit and the current state
# d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
# `git di $number` shows the diff between the state `$number` revisions ago and the current state
# di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d"
# Pull in remote changes for the current repository and all its submodules
# p = !"git pull; git submodule foreach git pull origin master"
# Clone a repository including all submodules
# c = clone --recursive
# Commit all changes
# ca = !git add -A && git commit -av
# Credit an author on the latest commit
# credit = "!f() { git commit --amend --author \"$1 <$2>\" -C HEAD; }; f"
# Interactive rebase with the given number of latest commits
# reb = "!r() { git rebase -i HEAD~$1; }; r"
# Remove the old tag with this name and tag the latest commit with it.
# retag = "!r() { git tag -d $1 && git push origin :refs/tags/$1 && git tag $1; }; r"
# Remove branches that have already been merged with master
# a.k.a. ‘delete merged’
# dm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
# List contributors with number of commits
# contributors = shortlog --summary --numbered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment