git: blank commit
• 180 words • 1 min • updated
⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.
How can we create an empty commit in git?
#
shell
mkdir repo
cd repo
git init
git commit --allow-empty -n -m "blank commit"
shell
% git log
commit effe4480543051e13838d4fbc127f01f658c07dc (HEAD -> master)
Author: Thiago Perrotta <{redacted-email}>
Date: Fri Feb 14 13:52:19 2025 +0100
blank commitWhy is this useful? #
-
dependabot cannot access secrets in github actions. There’s one workaround: check out the pull request locally, add a blank commit on top of it, then push it back. Boom. The secrets are suddenly accessible.
-
create a commit in advance of coding it, à la TDD. Declaring your intent first can help with focus and scope. You can always update the commit message afterwards with
git commit --amend1.
2.1) create a pull request (merge request) in advance of coding it. So that you can have a PR number that can be shared with your teammates and/or linked to from your bug tracker software.
My aliases #
shell
% grep -E '(alias|blank|desc)' ~/.gitconfig
[alias]
blank = desc -m \"blank commit\"
desc = commit --allow-empty -n-
Which I alias to
git reword. ↩︎