Skip to content

Instantly share code, notes, and snippets.

Last active June 22, 2022 09:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Git Cheatsheet

Git Cheatsheet

N. P. O'Donnell, 2020


List all commits on all remotes:

for c in $(git rev-list --remotes); do git show $c | head -n8; done | less


Commit with empty commit message

git commit --allow-empty-message -m ""


Remove untracked files (dryrun):

git clean -d -n

Remove untracked files (for real):

git clean -d -f


Moving HEAD Back and Forth Along the History

Next commit:

function n() {
    git log --reverse --pretty=%H master | grep -A 1 $(git rev-parse HEAD) | tail -n1 | xargs git checkout

Previous commit:

function p() {
    git checkout HEAD^1


View the reflog:

git reflog

Revert to a point in the reflog (e.g.: HEAD@{10}):

git reset --hard HEAD@{10}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment