Skip to content

Instantly share code, notes, and snippets.

@davidnaviaweb
Created September 6, 2019 12:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidnaviaweb/cdf235d419d3bb6569712faafeba306b to your computer and use it in GitHub Desktop.
Save davidnaviaweb/cdf235d419d3bb6569712faafeba306b to your computer and use it in GitHub Desktop.
A bunch of useful git shorthand commands.
## Logs ##
# pretty log #
l = log --pretty=format:"%C(Yellow)%H\\ %C(reset)%ad\\ %C(Green)%cr%C(reset)%x09\\ %Cred%d\\ %C(Cyan)%an:\\ %C(reset)%s" --decorate --date=format:%c
# tree log #
lg = log --graph --oneline --decorate --all
## Add ##
# add #
a = add
# add all indexed modified files #
au = add -u
# add all files in the current folder and its subfolders #
aa = add .
## Commit ##
c = commit --verbose
# commit with message # Example: $gcm "this is the commit message"
cm = commit -m
# commit with ammend #
am = commit --amend --verbose
# undo last commit #
uc = reset --soft HEAD~1
# undo last commit Chuck Norris' style #
ucf = reset --hard HEAD~1
## Add & Commit ##
# add all indexed modified files & commit with message # Example: $ gaum "this is the commit message for my already indexed modified files"
aum = !git add -u && git commit -m
# Add all indexed modified files & commit with ammend #
auca = !git add -u && git commit --amend
## Diff ##
d = diff
# simple summary diff #
ds = diff --stat
## Push ##
p = push
# push and set upstream to the same origin branch #
po = "!git push --set-upstream origin \"$(git bn)\""
## Remotes ##
# update branches in the remote #
ub = fetch --prune
# update branches in the remote and clear our local branches #
ubc = remote prune origin
# set upstream to same origin branch name #
su = "!git branch --set-upstream-to=origin/\"$(git bn)\" \"$(git bn)\"
## Pull ##
pl = pull
# pull all #
pla = pull --all
## Status ##
# status summary #
s = status -s
## Checkout ##
co = checkout
# checkout to new branch # Example: $ gcob bar -> creates new branch 'bar' from the current one
cob = checkout -b
## Branch ##
# list branches sorted by last modified
b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
# rename branch # Example: $ gbm foo -> renames our current branch to 'foo'
bm = branch -m
# list all local and remote branches #
ba = branch -a
# delete branch # Example: $ gdb foo -> removes branch 'foo'
bd = branch -d
# delete branch without checking if it's a good idea # Example: $ gdbf foo -> removes branch 'foo' without asking
bdf = branch -D
# branch name, it's only used for other commands #
bn = "!git rev-parse --abbrev-ref HEAD"
## Stashing ##
sh = stash
# stash save # Example: $ gsh baz -> saves our stash with the 'baz' tag
shs = stash save
# stash pop #
shp = stash pop
# stash list #
shl = stash list
## Cherry picking ##
# cherry pick a commit # Example: $ gcp HASHOFTHECOMMIT -> applies the commit to the current branch
cp = cherry-pick
## List aliases ##
# list all the aliases in this file #
la = "!git config -l | grep alias | cut -c 7-"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment