Skip to content

Instantly share code, notes, and snippets.

@LordPachelbel
Last active March 24, 2023 13:53
Show Gist options
  • Save LordPachelbel/b60d4a8de289a1d254d5855120cba403 to your computer and use it in GitHub Desktop.
Save LordPachelbel/b60d4a8de289a1d254d5855120cba403 to your computer and use it in GitHub Desktop.
My .gitconfig
[user]
name = FILL THIS IN
email = FILL THIS IN
[text]
autocrlf = input
eol = lf
text = auto
[color]
ui = auto
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
required = true
[alias]
# some of the following aliases came from https://haacked.com/archive/2014/07/28/github-flow-aliases/ and some of the comments
co = checkout # 'git co branchName' -- check out a branch
ec = config --global -e # edit this file
fa = fetch --all
fap = fetch --all --prune
up = !git pull --rebase --prune $@ && git submodule update --init --recursive # update local branch with latest stuff from origin and rebase any local commits
cob = checkout -b # 'git cob branchName' -- create a branch and check it out
p = push # push the current branch
pu = push -u # push the current branch and track upstream changes - use this when you're pushing a new branch
pf = push --force # force-push the current branch to overwrite the remote branch
mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' - # 'git mr origin 5' -- check out a GitLab merge request by its upstream name and ID -- from https://docs.gitlab.com/ee/user/project/merge_requests/#checkout-merge-requests-locally
b = branch # list local branches
br = branch -r # list remote branches
ba = branch -a # list all branches (both local and remote)
bm = branch --merged # list merged local branches
bu = branch --no-merged # list unmerged local branches
bam = branch -a --merged # list merged remote branches
bau = branch -a --no-merged # list unmerged remote branches
bv = branch -av # list all branches and their latest commits
bvv = branch -avv # list all branches, their latest commits, and their upstream branch names
bdl = branch -d # delete a local (merged) branch
bdr = push origin --delete # delete a remote branch
bd = !git bdr $1 && git bdl # delete a branch in both the remote and local repos
tempignore = update-index --assume-unchanged # temporarily ignore changes to a file, for those times when using .gitignore would be inconvenient -- see also https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree
tempunignore = update-index --no-assume-unchanged # stop ignoring changes to a file
listignored = !git ls-files -v | grep ^[a-z] # list temporarily ignored files
aa = add -A # stage everything: new files, changed files, and deleted files
ap = add -p # stage pieces of a file (hunks) using the interactive patch command
cm = !git add -A && git commit -m # commit everything (new, changed, deleted)
save = !git add -A && git commit -m 'SAVEPOINT' # save everything (new, changed, deleted) as a temporary commit instead of using the stash (think of it like a per-branch stash) -- use with 'undo' below
wip = !git add -u && git commit -m 'WIP' # "work in progress" -- save changes to tracked files as a temporary commit instead of using the stash (think of it like a per-branch stash) -- use with 'undo' below
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard # a safer way to 'reset --hard' because it does a commit before changing the working directory; this way you can use 'git reflog' to find that commit's SHA in case you need to get that commit back
undo = reset HEAD~1 --mixed # undo most recent commit but keep all its changes in the working directory -- use also with 'save', 'wip', and 'wipe'
amend = commit -a --amend # change most recent commit message and/or add more changes to the commit (use `git commit --amend` if you want to change the message but not add untracked changes)
mg = merge --no-ff # do a merge commit
undomg = reset --merge ORIG_HEAD # undo the most recent merge commit
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f" # delete branche that have been merged into master (run it from master branch)
bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f" # pull master before deleting merged branches
find = "!f() { git branch | grep -i " $1 "; }; f" # find branches whose names match a pattern, e.g. "git find sidebar" -- from http://blog.stvjam.es/2014/12/im-feeling-lucky-for-git-command-line/
lucky = "!f() { git branch | grep -i " $1 " | head -1 | xargs -r git checkout; }; f" # check out the first branch whose name matches a pattern, e.g. "git lucky align" for the branch "12345-fix-for-sidebar-alignment" -- also from http://blog.stvjam.es/2014/12/im-feeling-lucky-for-git-command-line/
remote-m = "!f() { for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format=\"%ci %cr %an\" $branch | head -n 1` \\\t$branch; done | sort -r; }; f" # list merged remote branches along with the timestamp and author of their latest commits
remote-u = "!f() { for branch in `git branch -r --no-merged | grep -v HEAD`; do echo -e `git show --format=\"%ci %cr %an\" $branch | head -n 1` \\\t$branch; done | sort -r; }; f" # list unmerged remote branches along with the timestamp and author of their latest commits
diffcm = diff HEAD~1 HEAD # show what changed in the most recent commit
diffcm2 = diff HEAD~2 HEAD~1 # show what changed in the second-most-recent commit
lg = log --graph --oneline --decorate --all --color # show the log as a tree
lgt = !"git lg --simplify-by-decoration" # show the log as a tree, but only show the tagged commits
lgs = log --graph --oneline --decorate --all --color --name-status # show the log as a tree and list the changed files
l1 = log --oneline # show the log as a list of commit messages
# log aliases from https://stackoverflow.com/a/34467298/5760141
lg1 = !"git lg1-specific --all"
lg2 = !"git lg2-specific --all"
lg3 = !"git lg3-specific --all"
lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
lg3-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n'' %C(white)%s%C(reset)%n'' %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)'
# show tag history, useful for seeing deployment messages from Pantheon tags
# based on https://stackoverflow.com/a/26563410/5760141 and https://stackoverflow.com/questions/12219604/list-git-tag-names-dates-and-messages#comment43237216_27395179
# TODO: make the output prettier with colors and stuff
tags = !git taghist
taghist = for-each-ref --format=\"%(refname:short) %(taggerdate) %(subject) %(body)\" refs/tags
st = status # show status
s = status -s # show status in the short format
ss = status -s # show status in the short format
lsch = ls-files -dmo --exclude-standard # list changed files -- for scripts this is easier to handle than trying to parse git status output
# create a patch from the most recent commit
patchfromcommit = format-patch -1 HEAD
# create a patch from a specific commit -- usage: patchfromhash abcd1234
patchfromhash = format-patch -1
# create a patch file from a merge commit -- creates the file mergecommit.patch
patchfrommerge = !git log -p --reverse --pretty=email --stat -m --first-parent HEAD~1..HEAD > mergecommit.patch
# apply a patch as much as possible and create .rej files of the rejected portions so they can be manually patched
applywithrejects = apply --reject --whitespace=fix
awr = !"git applywithrejects"
[push]
default = simple
followTags = true
[core]
editor = vi
[branch "master"]
remote = origin
merge = refs/heads/master
[branch]
autosetupmerge = true
[remote "origin"]
push = HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment