How to Push an Empty Git Commit?

How to Push an Empty Git Commit?

You might be asking why would one push an empty commit.

Here is one of the reasons that I come across.

I wanted to trigger the pipeline without making any coding changes to the feature branch. Pushing an empty commit is the solution.

It is a two-step procedure to Push Empty Git Commit.

1. Create an empty commit

Make sure you are using the correct feature branch and it is up to date. Run the below command to create an empty commit.

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

The flag --allow-empty is the must-have tag. That allows you to create a commit even without making any coding changes.

You can add any message for the flag option -m.

2. Push commit to remote repo branch

Use git push command as usual we use it for pushing local commit to remote branch.

git push

It will push the commit to the currently selected branch.

You can also specify the branch name.

git push origin <branch-name>

Pushing an empty commit is very useful in certain situations like triggering a build or development pipeline.

Leave a Reply

Your email address will not be published. Required fields are marked *