While Git supports aliases and I am a big fan of Git aliases, (e.g. ‘git lg’), the most valuable to me (and most used) aliases are shell aliases (e.g. ‘gc’ for ‘git commit’).
Dev Tips
GitHub Tab Size Preference
As a WordPress developer, I deal with lots of code indented with tabs (rather than spaces). By default when viewing these files in GitHub, each tab is rendered as 8 spaces. On my personal machine, I render each tab as 4 spaces. This difference makes it less pleasant to view code in GitHub, however, I just learned I can set my preferred tab rendering in GitHub!
Git Rebase and the Multiverse
In “Git Merge and the Multiverse” I looked at merging branches and how sometimes this results in a fast-forward merge and sometimes in the creation of a merge commit. Now let’s look at Git rebase (a.k.a. the power to rewrite history).
Git Merge and the Multiverse
If you’re a fan of science (or science fiction), you may be familiar with the concept of the “Multiverse”, the idea that there are multiple universes. In some science fiction stories, one universe can split, branching into multiple universes and then later collapse into a single universe, this is a surprisingly good analogy for Git and branching.
Set Number of Characters in Commit Hash for git log
When I’m writing examples, it is often nice to have very short commit hashes. The ‘–abbrev=3’ argument, passed after the ‘–oneline flag, allows me to reduce the number of characters in the commit to 3.
GitHub Link to Commit instead of Branch
When linking to specific lines in a file to GitHub, it is preferable to link to those lines in the file for a specific commit (rather than for a specific branch). This is because the contents of a branch can change but the contents of a commit remain the same forever.
Why PHP require autoload.php should be wrapped in is_readable()
When using Composer for PHP class autoloading, it is a good practice to wrap your require statement with an is_readable() check. Here are some notes on why this is an important thing to do.
How to Close and Re-Open WordPress Gutenberg Sidebar
The sidebar gets a lot of use in the WordPress Block Editor, a.k.a. Gutenberg, but I found myself in a situation where I needed to programmatically close the sidebar and then re-open it later. This is how I did it.
Get Last Modified Value of a WordPress Post
When reading an article online, I find it helpful to know when the article was last updated. Not all blogs display the last updated value however even when the last updated value is not displayed, the value is accessible via the WordPress REST API. This is how I retrieve the last modified value from the WordPress REST API.
Pretty Print JSON URL
I work a lot with JSON endpoints and having a browser extension to pretty print the JSON response is invaluable. However, sometimes I’m using a different machine (or guiding someone on their machine) and rather than asking them to install a browser extension, I use this trick. If the user is on the page displaying the JSON response, running this command in the browser console will pretty print the response await (await fetch(window.location.href)).json().