Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Last active March 9, 2023 11:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeinthehole/081697fb457ec027ff4ce3175251edfe to your computer and use it in GitHub Desktop.
Save codeinthehole/081697fb457ec027ff4ce3175251edfe to your computer and use it in GitHub Desktop.
Git config
[user]
name = David Winterbottom
email = david.winterbottom@gmail.com
[alias]
# SHORT VERSIONS
co = checkout
ci = commit
cn = commit --no-verify
st = status
# Remove changes from index
unstage = reset HEAD --
# Revert changes
restore = checkout --
# Colored history view
hist = log --color --pretty=format:\"%C(yellow)%h%C(reset) %s%C(bold red)%d%C(reset) %C(green)%ad%C(reset) %C(blue)[%an]%C(reset)\" --relative-date --decorate
# PULL-REQUEST HELPERS
# Open the pull request page for current branch (if one exists)
openpr = "!f() { github-open-pr-page; }; f"
# Print the Github URL for current branch (if one exists)
prurl = "!f() { github-pr-url; }; f"
# Show files changed on branch
prfiles = diff --relative --name-only origin/master...HEAD
# Show diff of PR (same as what GH will show)
prdiff = diff origin/master...HEAD
# Run checks on PR
prcheck = "!f() { git-check-pr; }; f"
# Run linter on PR commits
prlintall = "!f() { git-run-command-on-revisions origin/master head 'flake8'; }; f"
# Run linter on changed files
prlint = "!f() { cd `git rev-parse --show-toplevel` && git prfiles | xargs flake8; }; f"
# Run unit tests on PR commits
prtestall = "!f() { git-run-command-on-revisions origin/master head 'py.test tests/unit/'; }; f"
# OPEN THE GITHUB PAGE FOR THE...
# ...repo homepage (included for consistency)
open = !hub browse --
# ...repo commits
opencommits = !hub browse -- commits
# ...commit page for HEAD
openhead = !hub browse -- commit/$(git rev-parse HEAD)
# ...commit page for a passed SHA (defaults to HEAD)
opencommit = "!f() { sha=$(git rev-parse ${1:-HEAD}); hub browse -- commit/$sha; }; f"
# ...blame page for the passed file (a line number/range can be passed in too)
openblame = "!f() { sha=$(git log --format='%h' -1 $1); hub browse -- blame/$sha/$1#L$2; }; f"
# ...commit history page for the passed file
openhistory = "!f() { sha=$(git log --format='%h' -1 $1); hub browse -- commits/$sha/$1; }; f"
# ...CI detail page
openci = "!f() { url=$(hub ci-status -v | cut -d' ' -f2); open \"$url\"; }; f"
# ...commit page for the conflicting commit during a rebase
openconflict = "!f() { hub browse -- commit/$(git rev-parse REBASE_HEAD); }; f"
# ...repo issues
issues = !hub browse -- issues
# ...repo pull requests
pulls = !hub browse -- pulls
# ...MY repo pull requests
mypulls = !hub browse -- pulls/codeinthehole
# ...repo wiki
wiki = !hub browse -- wiki
# ...repo settings
settings = !hub browse -- settings
# ...repo branches
branches = !hub browse -- branches
# ...repo branches
releases = !hub browse -- releases
# GET THE URL FOR...
# ...HEAD
headurl = "!hub browse -u -- commit/$(git rev-parse HEAD)"
# ...HEAD (into clipboard)
copyheadurl = "!git headurl | pbcopy"
# ...A given commit
url = "!f() { sha=$(git rev-parse ${1:-HEAD}); hub browse -u -- commit/$sha; }; f"
# ...A given commit (into clipboard)
copyurl = "!git url $1 | pbcopy"
# PRINT OUT THE...
# ...SHA of HEAD
headsha = rev-parse HEAD
# ...the current branchname
branchname = !git rev-parse --abbrev-ref HEAD
# ...incoming commits
incoming = "!git hist ..origin/$(git branchname)"
# ...outgoing commits
outgoing = "!git hist origin/$(git branchname).."
# ...live commit
prod = "!f() { sha=$(http https://octopus.energy | ag SHA | awk '{print $3}'); git show $sha; }; f"
# ...test commit
test = "!f() { sha=$(http https://octopus.systems | ag SHA | awk '{print $3}'); git show $sha; }; f"
# ...authors for a file
authors = "!f() { git log --format='%an' \"${GIT_PREFIX}$1\" | sort | uniq | paste -sd ', ' -; }; f"
# ...author summary for each file in a folder
folderauthors = "!f() { ls \"${GIT_PREFIX}${1:-.}\" | while read filename; do echo \"$filename - $(git authors ${GIT_PREFIX}${filename})\"; done; }; f"
# ...commit SHA for the target branch of a rebase
rebaseonto = "!f() { cd $(git rev-parse --show-toplevel); cat .git/rebase-apply/onto; }; f"
# UTILITIES TO...
# Start afresh on master
zero = "!git co master && git pull --ff-only && git cleanup;"
# ...delete merged branches
cleanup = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
# ...open GUI
visualise = !gitk
# ...push current branch to origin and set as a tracking branch
publish = !git push -u origin $(git branchname)
# ...delete remote branch
unpublish = !git push -u origin :$(git branchname)
# ...push a branch and create a pull request (use first commit as PR title and copy URL to clipboard)
newpr = !git publish && hub pull-request --copy --no-edit
# ...push a branch and create a pull request (open editor for PR title/description).
createpr = !git publish && hub pull-request --browse
# ...commit everything as a WIP commit (bypassing pre-commit checks)
wip = !git add --all && git commit --no-verify -m wip
# ...reset last commit (used after 'git wip')
pop = reset head^
# ...resync branch with remote (which has been force-pushed)
resync = !git reset --hard $(git rev-list master.. | tail -1)^ && git pull
# ...delete local branches deleted from remote
prune = fetch --prune
# ...squash changes into last commit and f-push up
oops = !git commit --all --amend --no-edit && git push --force
[rebase]
# The format of commits in Vim when doing an interactive rebase.
instructionFormat = %s [%an, %ar]
autosquash = true
[apply]
whitespace = strip
[pager]
diff =
color = true
[status]
color = true
showUntrackedFiles = all
[color]
ui = true
[help]
autocorrect = 1
[push]
default = upstream
[core]
excludesfile = ~/.gitignore_global
pager = less -F -X
attributesfile = ~/.gitattributes_global
[filter "nbstrip_full"]
clean = "jq --indent 1 \
'(.cells[] | select(has(\"outputs\")) | .outputs) = [] \
| (.cells[] | select(has(\"execution_count\")) | .execution_count) = null \
| .metadata = {\"language_info\": {\"name\": \"python\", \"pygments_lexer\": \"ipython3\"}} \
| .cells[].metadata = {} \
'"
smudge = cat
required = true
[diff]
tool = vimdiff
compactionHeuristic = true
noprefix = true
[merge]
conflictstyle = diff3
tool = vimdiff
[mergetool]
prompt = false
keepBackup = false
[credential]
helper = osxkeychain
[commit]
template = /Users/david/.gitcommitmsg.txt
[rerere]
enabled = 1
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[branch]
autosetuprebase = always
@codeinthehole
Copy link
Author

codeinthehole commented Feb 23, 2017

Plus these bash aliases:

# Git
# ---

# Wrap git with hub
alias git='hub'

# Common actions
alias g='git status -sb'
alias gh='git hist'
alias gz='git zero'

# Fancy version of git branch
alias gb='git --no-pager branch --sort=committerdate --format="%(color:yellow)%(refname:short) %(color:green)%(committerdate:relative) %(color:blue)[%(authorname)]" --color=always'
alias ga='git add'
alias gd='git diff --relative --color-words'
alias gdc='git diff --cached -w'
alias gpf='git push --force-with-lease'

# Check out a new branch (ie start a new PR)
alias gco='git checkout -b '

# PR rebasing
# -----------
# 
# Show commits in master not in PR branch
alias ghm='gh origin/master..'

# Rebase all commits in current feature branch (super-useful)
alias grb='git rebase -i `git rev-list origin/master.. | tail -1`^'

# Rebase against origin/master and set author-dates to same as committer dates (so the order
# stays the same in Github).
alias grm='git rebase origin/master --ignore-date'

alias gf='git fetch --prune'
alias gaa='git add -A'
alias gc='git commit -v'
alias gcn='git commit --no-verify -v'
alias gca='git commit --amend --no-edit'
alias gcan='git commit --amend --no-edit --no-verify'
alias gcf='git fixup'
alias gdw='git diff --no-ext-diff --word-diff'
alias gt='git tag'

alias gri='git rebase -i'
alias grc='git rebase --continue'
alias grs='git rebase --skip'

alias gsl='git stash list'
alias gss='git stash save'
alias gsp='git stash pop'
alias gcp='git cherry-pick -x'
alias gcb='git checkout -b'

alias gmt='git mergetool'

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