Perform an Empty Commit in Git without anything in Staging Area


At times you may want to manually initiate and trigger a build to generate an artifact or kick-start a workflow but it only works when a code commit happens.

If you do not have anything to commit to your git repo, in such cases usually a hack people do is to change a code file (such as a comment line) and add to the staging area and commit-push.

Clean way to perform an empty commit

Make use of the flag --allow-empty with the git commit command,

Example:
% git commit --allow-empty -m "Empty commit"
[main 549a3bf] Empty commit
% git log --oneline
549a3bf (HEAD -> main) Empty commit
6ac92d6 4th commit
06250f0 3rd commit
2712514 2nd commit
a3e24f4 1st commit
Git Cleaner way for an empty Commit Example
-




Have Questions? Post them here!