Skip to content

Instantly share code, notes, and snippets.

@shreeve
Last active December 16, 2022 04:54
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 shreeve/e591d0098d95b6da6ce41d8a8d11a2f6 to your computer and use it in GitHub Desktop.
Save shreeve/e591d0098d95b6da6ce41d8a8d11a2f6 to your computer and use it in GitHub Desktop.
Git config file
# =============================================================================
# .gitconfig
#
# Author: Steve Shreeve <steve.shreeve@gmail.com>
# Date: Dec 15, 2022
# =============================================================================
# curl -Lso ~/.gitconfig http://bit.ly/3FANcK7
[user]
name = Steve Shreeve
email = steve.shreeve@gmail.com
[github]
user = shreeve
[color]
diff = auto
status = auto
branch = auto
interactive = auto
[core]
excludesfile = ~/.gitignore
pager = "less -FRSX"
quotepath = false
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[http]
postBuffer = 524288000
[pager]
status = true
[push]
default = current
followTags = true
[alias]
a = add # add to .git
ap = add --patch # interactively add hunks within files
b = branch # create a new branch
ba = branch -rv # show all remote branches verbosely
lnuke = branch -D # force delete local branch
rnuke = push origin --delete # force delete remote branch
x = checkout # checkout a specific branch
xx = checkout -- # restore last version
xf = checkout --patch # need to append <branch> and <file>
xb = checkout -B # create a new local branch (if it already exists, then force reset it)
nb = checkout -b # create a new local branch (if it already exists, then fail)
pick = cherry-pick # cherry-pick one commit
c = commit # commit a file
cam = commit -a -m # commit all changes (not new files though) and a message
e = commit --allow-empty --allow-empty-message -m '' # make an empty commit (with an empty message)
d = diff # show a diff
w = diff --cached # show "what" is about to be committed
dn = diff --name-only # show names of changed files
f = fetch # fetch from remote
lp = log -p # show a nice diff of all commits
lz = log -p HEAD~1..HEAD~0 # show last commit
u = pull --ff-only # fetch and *merge* in changes from remote
up = pull --rebase --autostash # before the rebase, stash mods then apply when done
p = push # push changes to remote
force = push --force-with-lease # force push (somewhat safely)
# resets, so many flavors!
unstage = reset # rs
us = reset # unstage
rs = reset # RK: reset index and keeps working tree
rsh = reset --hard # RR: reset index and reset working tree
rss = reset --soft # KK: keeps index and keeps working tree
rs1 = reset HEAD~1 # RK: undo 1 commit, reset index and keeps working tree
rsh1 = reset --hard HEAD~1 # RR: undo 1 commit, reset index and reset working tree
rss1 = reset --soft HEAD~1 # KK: undo 1 commit, keeps index and keeps working tree
lose = reset --hard # rsh
rewind = reset --soft # rss
undo = reset HEAD~1 # rs1
oops = reset --hard HEAD~1 # rsh1
uncommit = reset --soft HEAD~1 # rss1
s = status # check the repo status
# tracking
untrack = rm --cached # stop tracking a file, but keep the current file on disk
unwatch = update-index --assume-unchanged # temporarily stop watching this file for changes
watch = update-index --no-assume-unchanged # resume watching this file
# logging
ref = reflog -20 # shows the last 20 positions, with a little description
l = log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset - %Cblue[%an]%Creset%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'
ld = log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset - %Cblue[%an]%Creset%C(yellow)%d%Creset %s %Cgreen(%ci / %cr)%Creset'
ls = log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset - %Cblue[%an]%Creset%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --name-status
lsd = log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset - %Cblue[%an]%Creset%C(yellow)%d%Creset %s %Cgreen(%ci / %cr)%Creset' --name-status
# scripts
back = !"'!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f" # see: https://bit.ly/2YBjm12
bi = !"for ref in $(git for-each-ref --sort=-committerdate --format='%(refname)' refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:'%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n' | cat ; done | uniq" # information about each branch
o = !"git fetch; git diff -w main origin/main" # fetch latest and diff against it, without pulling or merging
# ==[ How to permanently remove a file from a repo ]==
#
# # remove all references to the file
# git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch lib/sample.png' --prune-empty --tag-name-filter cat -- --all
#
# # force push the changes
# git push origin --force --all
#
# # after time has passed and you're sure there are no issues, purge your local references
# git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
# git reflog expire --expire=now --all
# git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment