$ command-helper

Git

Branches, commits, undoing changes, rebase, stash and searching history.

Requires Google sign-in

Everyday

Working tree status
git status -sb
Create a branch and switch to it
git switch -c <branch>
Commit all tracked changes
git commit -am "message"
Push a new branch
git push -u origin <branch>
Pull with rebase
git pull --rebase
Compact history graph
git log --oneline --graph --decorate -20

Undoing changes

Discard changes in a file
git restore <file>
Unstage a file
git restore --staged <file>
Amend the last commit
git commit --amend --no-edit
Undo the last commit, keeping changes
git reset --soft HEAD~1
Create a commit that reverts another
git revert <commit>
Recover a “lost” commitadvanced
git reflog

Find the hash you need and run git reset --hard <hash> or git cherry-pick <hash>.

Stash

Stash changes, including new files
git stash -u
List stashes
git stash list
Apply the latest stash
git stash pop

Advanced

Interactive rebase of the last N commitsadvanced
git rebase -i HEAD~<n>
Copy a commit onto the current branchadvanced
git cherry-pick <commit>
Find the commit that introduced a stringadvanced
git log -S "<text>" --oneline
Who last changed lines of a file
git blame -L 10,30 <file>
Binary search for the commit that introduced a bugadvanced
git bisect start && git bisect bad && git bisect good <commit>
Delete local branches already merged into mainadvanced
git branch --merged main | grep -v -E '^\*|main' | xargs -r git branch -d