DEV Community

Cover image for How to do empty commit in git and why?

Posted on • Updated on • Originally published at

How to do empty commit in git and why?

Did you know you can make empty commits in git?

Have you ever needed to trigger a CI build but couldn't because manual re-trigger was not an option?
If so, you might be tempted to make a meaningless change to your source file only to make a git commit just to re-trigger the CI pipeline.

What if I told you there was a better way to do it? 🧐

Empty commit

Yes! You can make a git commit without making any changes to your source file(s) whatsoever. For example:

git commit --allow-empty -m "Trigger CI build"
Enter fullscreen mode Exit fullscreen mode

I hope you find this tip interesting and helpful.
If you did, please give it a like and share it with someone who might benefit from it.

My name is Ashutosh, and I work as a software engineer. I love to share my learning with the community.
You can connect with me on LinkedIn and follow me on Twitter.

Top comments (1)

anshuman_bhardwaj profile image
Anshuman Bhardwaj

Thanks, Ashutosh. I learned something new today.