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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap