Skip to content

Instantly share code, notes, and snippets.

@rubinlinux
Created May 19, 2021 23:37
Show Gist options
  • Save rubinlinux/c60a819c30efd88ba1b7a89ddc87b50b to your computer and use it in GitHub Desktop.
Save rubinlinux/c60a819c30efd88ba1b7a89ddc87b50b to your computer and use it in GitHub Desktop.
[alias]
##########################
## Cheat sheet ##
##########################
## Info:
## status - show where you are in the repository, what files are in what state, branch, etc
## br - fancy branch list (does not work on deb 9)
br = branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate
## lb - list recently used branches
lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\" \\033[33m%s: \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'
## brlog - Show changes in current branch that arent in master
brlog = log --stat HEAD --not master --no-merges
## ignored - show ignored files
ignored = !git ls-files -v | grep "^[[:lower:]]"
##
## Basic:
## fetch - sync the db but dont merge or change anything
## pull - equivelent of git fetch; git merge origin/master
## diff file - show changes to local file
## diff file --cached - show changes to local file after you added it
##
## Workflow:
## con - create a new branch to do some work
con = "!f() { git checkout -b $1 && git push -u origin HEAD; }; f"
## cog - Checkout the first branch containing the given string
cog = "!f() { git branch | grep $1 | head -n1 | cut -c 3- | xargs git co;}; f"
## up - bring self up to date with origin
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
## save - put all modified and new files into a WIP: SAVEPOINT commit for safe keeping
save = !git add -A && git commit -m 'WIP: SAVEPOINT'
## undo - go back to previous commit, putting the undid commits changes back into uncommitted edits/files
undo = reset HEAD~1 --mixed
## wipe - saves everything just in case, then reset hard
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard
# (needed by bdone/bclean) Return the name of the default branch (usually master)
default = !git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
## bclean - Cleanup (delete) any branches already comitted
bclean = "!f() { DEFAULT=$(git default); git branch --merged ${1-$DEFAULT} | grep -v " ${1-$DEFAULT}$" | xargs -r git branch -d; }; f"
## add <file> - add files to the index (list of things to be committed)
## add -p [file] - add files to the index by asking for each chunk
## reset <file> - remove a file from the index
## commit -m "message" - Commit everything in the index
## push - send commits to the server
## bdone - call when done with a branch forever, goes back to master, cleans up, pulls/rebases updates
bdone = "!f() { DEFAULT=$(git default); git checkout ${1-$DEFAULT} && git up && git bclean ${1-$DEFAULT}; }; f"
## com - Checkout master
com = checkout master
##
## Handy:
## skip - temp ignore set of changes to a file (ie, dbInit database pointer change)
skip = update-index --assume-unchanged
## cheat - Show this page
cheat = "!grep \\#\\# ~/.gitconfig "
@rubinlinux
Copy link
Author

rubinlinux commented May 19, 2021

The output looks like this:

┌─[rubin@blarg][~/git/foo] [master Ⓤ ] 
└──╼ git cheat
    ##########################
    ## Cheat sheet          ##
    ##########################
    ## Info:
    ##   status - show where you are in the repository, what files are in what state, branch, etc
    ##   br - fancy branch list (does not work on deb 9)
    ##   lb - list recently used branches
    ##   brlog - Show changes in current branch that arent in master
    ##   ignored - show ignored files
    ##  
    ## Basic:
    ##   fetch - sync the db but dont merge or change anything
    ##   pull - equivelent of git fetch; git merge origin/master
    ##   diff file - show changes to local file
    ##   diff file --cached - show changes to local file after you added it
    ##
    ## Workflow:
    ##   con - create a new branch to do some work
    ##   cog - Checkout the first branch containing the given string
    ##   up - bring self up to date with origin
    ##   save - put all modified and new files into a WIP: SAVEPOINT commit for safe keeping
    ##   undo - go back to previous commit, putting the undid commits changes back into uncommitted edits/files
    ##   wipe - saves everything just in case, then reset hard
    ##   bclean - Cleanup (delete) any branches already comitted
    ##   add <file> - add files to the index (list of things to be committed)
    ##   add -p [file] - add files to the index by asking for each chunk 
    ##   reset <file> - remove a file from the index
    ##   commit -m "message" - Commit everything in the index
    ##   push - send commits to the server
    ##   bdone - call when done with a branch forever, goes back to master, cleans up, pulls/rebases updates
    ##   com - Checkout master
    ##
    ## Handy:
    ##   skip - temp ignore set of changes to a file (ie, dbInit database pointer change)
    ##   cheat - Show this page

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