gh (pronounced… “guh”?) is GitHub’s official command line interface (CLI) tool. It lets you interact with GitHub directly from the command line, supporting most key features across more than 25 commands and over 200 subcommands. It’s also great for bridging the terminal-browser gap, allowing you to jump to pages relevant to your current context, such as the PR for the current branch.
When you want to count the number of files within a Git repository, it's generally best to use Git itself for the task because it will skip over any generated or downloaded files. Here is a command chain to use to count all committed files within the current directory:
Recently, I was working in a new repository and found the git blame output often pointed back to a large repository-wide formatting commit (applying Black to all Python files). To ignore this commit in git blame, I added its SHA to a .git-blame-ignore-revs file, per this documentation:
Typically, we share repositories through a Git host, like GitHub, allowing others to clone the repository to get a copy. But sometimes that’s not an option, for example when trying to get someone started on your project when corporate onboarding processes take days to grant GitHub access.
Git supports storing symbolic links (symlinks) in your repository, which are filesystem links that point to another file or directory. These are great for when you want to have the same file at multiple locations in your repository, such as some configuration file that is used for multiple sub-projects. But how can you list all the symlinks in your repository?
Today I have released the second update to Boost Your Git DX, my book of developer experience (DX) recommendations for using Git. Since the last update (2024-04-04), it has grown again by 28 pages, for a new total of 391 pages!
hyperfine is a neat tool for benchmarking commands. If you provide it multiple commands, its output includes a comparison, saying which is the fastest, and by how much.
By default, Git only colourizes in its output when writing to an interactive terminal. Sometimes, this heuristic isn’t accurate, for example, when you’re piping Git output through another command. In such cases, you can force colourization on or off with either the color.ui configuration option or the --color option. Let’s look at both in turn.
git rev-list lists details about commits (also known as “revisions”, hence the name). Its --count option outputs the count of commits in the given range. Pass it @, the short alias for HEAD, to count commits on the current branch:
Git doesn’t store reversion links between commits. It only relies on commit messages to track this information. When you run git revert, the default message includes a line about the reverted commit:
git shortlog generate statistics about the commits in a repository, intended to help generate project release notes. By default, it groups commits by author, but it can use other fields too. Use it for a more powerful dissection of a repository than tools like GitHub’s Insights tab.
Django’s release notes are extensive and describe nearly all changes. Still, when upgrading between Django versions, you may encounter behaviour changes that are hard to relate to any particular release note.
I have just released an update to my book Boost Your Git DX, six months after its initial release. This update adds some extra content and has a bunch of edits based on reader feedback. The PDF is now ten pages longer, for a total of 363.
git bisect efficiently searches for a commit responsible for changing a given behaviour. git log lets you see when a given file or line changed, but that’s often insufficient when the cause of some change is unclear. In such cases, git bisect shines, as it lets you check your running system.
Contrary to common belief, Git doesn’t store diffs. It actually stores snapshots of whole files, heavily compressed to reduce redundancy. Then when displaying a diff is required, git diff generates it on the fly.
My two “Boost Your DX” books are available in a bundle deal, saving $10 compared to buying them separately. Great for improving your Django and Git skills at the same time.
By default git status uses “long format”, which lists information explicitly. This format takes quite a lot of words and vertical space to split file status by section: