Git and GitHub

Git

Show all files in index

git ls-tree -r BRANCH_NAME --name-only

Remove ignored file from index

git rm --cached <path>

Rebuild Git index

Removes all tracked files that should be ignored

git rm -r --cached .
git add .

Find out why file is ignored

git check-ignore -v <pathname>

Restore a single file from main

git checkout origin/main -- path/to/file

Reset local branch from remote

@{u} represents the upstream branch that the current branch is tracking

git reset --hard "@{u}"

Stop tracking remote branch

git branch --unset-upstream

Drop a commit

Undo reset or dropped commit

git reflog
e192732d8 HEAD@{22}: reset: moving to HEAD
e192732d8 HEAD@{23}: commit: Add some stuff
555fe5cf7 HEAD@{24}: checkout: moving from main to cool-branch
62d93e725 HEAD@{25}: checkout: moving from cool-branch to main
555fe5cf7 HEAD@{26}: reset: moving to HEAD
git reset --hard HEAD@{23}
# or
git reset --hard e192732d8

Undo dropped stash

git fsck --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --merges --no-walk --grep=WIP
git stash apply <SHA>

Abort merge or rebase

git merge --abort
git rebase --abort

GitHub

Warning

Be careful when using the Hide Whitespace option in pull requests. This can mask indentation and bracket mismatch errors!

Filter pull requests & issues by author

author:@me
author:username

Filter pull requests by target branch

is:pr base:main

Sort pull requests by merge date

is:pr is:merged sort:updated-desc