Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active June 22, 2022 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/cb67ca0aa8cfff86bf4d24cef2087e56 to your computer and use it in GitHub Desktop.
Save npodonnell/cb67ca0aa8cfff86bf4d24cef2087e56 to your computer and use it in GitHub Desktop.
Git Cheatsheet

Git Cheatsheet

N. P. O'Donnell, 2020

Remotes

List all commits on all remotes:

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

Commits

Commit with empty commit message

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

Housekeeping

Remove untracked files (dryrun):

git clean -d -n

Remove untracked files (for real):

git clean -d -f

Navigation

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
}

Reflog

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