More in Git
List branches merged into main
Git
Finds the branches that are safe to delete, and the ones that are not.
Amend a commit without changing its message
Git
Adds forgotten files to the previous commit and leaves the message exactly as it was.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Search the whole history for a string
Git
Finds every commit whose diff added or removed a piece of text, including in files long since deleted.
Stop tracking a file without deleting it
Git
For the config file that should never have been committed. Add it to .gitignore afterwards.
Show what a merge will do before doing it
Git
Lists the commits and the files a merge would bring in, so a surprise is less likely.
Find the commit that introduced a bug
Git
Binary search across history. Mark a known good and a known bad commit and git narrows it down for you.
Random picks
Make a shell script fail loudly
Shell
The four lines that turn a script from 'carries on after an error' into 'stops at the first problem'.
Generate an SSH key and add it to the agent
Security
Ed25519 rather than RSA: shorter, faster, and no key-size decision to get wrong.
Nullable reference types in C#
Systems
Turning the feature on makes the compiler point at every place a null could slip through.
Narrow a union with a type guard
TypeScript
A predicate returning `x is T` teaches the compiler what a runtime check proved.
Walk a directory tree lazily
Python
pathlib keeps the paths as objects rather than strings, so joining and suffix checks stay readable.
Sum a column with awk
Text Processing
Adds the third field of every line and prints the total, ignoring anything non-numeric.
Watch a command until it succeeds
Shell
Retries every two seconds and stops the moment the command exits zero. Useful while waiting for a service to come up.
Security headers for an Express app
Security
The handful worth setting even when you are not using a framework that sets them for you.