Show Menu
Cheatography

git & github Cheat Sheet (DRAFT) by

Git and github commands

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basics

glo
git log --oneline --decorate
gsw
git switch
gswc
git switch -c {branc­h_name}
gswm
git switch ${git_­mai­n_b­ranch}
gcam
git commit -a(ll) -m(essage)
gaa
git add --all

Time travel

gco {commi­t-hash}
visit previous commit (detached HEAD)
gco HEAD~{n}
commit n before current head
gswc -
get back to prev checked out branch
gco HEAD {file(s)}
revert file(s) to last commit status
grss {commit} {file(s)}
restore files to state from given commit ref
grh {commit}
reset repo back to commit hash, commits are GONE
grhh {commit}
reset --hard - lose commits + ALSO REMOVE FROM WORKDIR
grev {commit}
revert - create commit undoing changes
 

Diff

gd
all diffs that are not staged
gd HEAD
changes since HEAD/last commit
gdca
only staged
gb {branc­h1..br­anch2}
diff btw branches (or commits)

Remote

gr -v
list remote URLs
gra {name} {url}
git remote add
ggp
git push origin ${curr­ent­_br­anch}
gpsup
git push --set upstream ...
gf
fetch (get changes to local repo but not to workdir)
gl
pull (default origin­/cu­rrent branch)

Rebase

grb
git rebase
grbm
rebase ${git_­mai­n_b­ranch}
grb -i HEAD~{n}
recreate commits from n ago until HEAD
[WARNING] Don't rebase commits that are shared with / used by others!
 

Stash

gsta
git stash (save)
gstp
git stash pop
gstaa
git stash apply (without popping)
gstl
git stash lit
gstc
git stash clear

Tags

gts
git tag -s(ign)
gtv
git tag | sort -V
gco {tag}
check out particular tag
g tag {tagname}
lightw­eight tag at HEAD
g tag -a {tagname}
annotated tag at head
g push --tags
push tags to origin

Reflogs

g reflog show {ref}
ref eg HEAD or branch
gco HEAD@{2}
2 moves ago in reflog
g reflog master­@{o­ne.w­ee­k.ago}
show reflog until 1 week back
gd master master­@{y­est­erday}
diff to yesterday
gco master­@{1.we­ek.ago}
checkout at closest matching entry
grh master@{n}
reset master to n moves ago
Reflogs are only local, and expire in ~90 days Records all moves of pointers & everything done in a repo locally, so we can revert things even after rebase, etc.