How to Push Empty Git Commits

Git does not allow commits without changes to the project but there are cases that might require you to push a commit without changing any file.

How to Push Empty Git Commits

Why would you do it?

Well, because you might need to trigger a build without making any changes to your project... and you might not have access to trigger the build manually.

How would you do it?

It's like pushing a normal commit, except you add the ---allow-empty flag.
So the entire command becomes:

git commit --allow-empty -m "Empty commit"

Git aliases

You could shorten the command with git aliases, which allow you to create shortcuts for frequently used git commands.
To setup a new git alias:

git config --global alias.empty 'commit --allow-empty -m'

Now, instead of writing git commit --allow-empty -m "Empty commit" you could simply use git empty "Empty commit" and be done.

Will soon write a more in-depth article about git aliases.

Mastodon Romania