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 {branch_name} |
gswm |
git switch ${git_main_branch} |
gcam |
git commit -a(ll) -m(essage) |
gaa |
git add --all |
Time travel
gco {commit-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 {branch1..branch2} |
diff btw branches (or commits) |
Remote
gr -v |
list remote URLs |
gra {name} {url} |
git remote add |
ggp |
git push origin ${current_branch} |
gpsup |
git push --set upstream ... |
gf |
fetch (get changes to local repo but not to workdir) |
gl |
pull (default origin/current branch) |
Rebase
grb |
git rebase |
grbm |
rebase ${git_main_branch} |
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} |
lightweight 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@{one.week.ago} |
show reflog until 1 week back |
gd master master@{yesterday} |
diff to yesterday |
gco master@{1.week.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.
|