Git: my git stash -p optimization in Git 2.55
I got another commit merged in Git 2.55 (2026-06-29), yay! The release note reads:
(All tags.)
git stash -p optimization in Git 2.55I got another commit merged in Git 2.55 (2026-06-29), yay! The release note reads:
ls-treeTo list all files in your repository as they were at a given commit, use git ls-tree with its -r and --name-only options:
git log with --perl-regexpgit log has an --author option to limit the output to commits from matching authors:
gh, the official GitHub CLIgh (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.
My new book, Boost Your GitHub DX is out now!
To check if a commit SHA exists on a given branch, you have a couple of options.
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:
git fast-exportTypically, 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?
You may encounter this warning when cloning a Git repository:
Last week, I released the second update to my book Boost Your Git DX. Today I’m happy to announce that I have released a free sample of the book.
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.
color.ui or --colorBy 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.
Okay, so you just ran git pull on a branch, and something broke, so you want to undo it. Here are two ways how.
rev-listgit 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:
shortloggit 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.
reset --hard, use reset --keep insteadWhen I started learning Git, I found many references covering two ways to undo commits with git reset:
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.
Say you have a commit SHA and want to know the first version it was released in. You can use this command:
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 bisectgit 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.
diff.algorithm=histogramContrary 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.