Skip to main content

How to Create and Push an Empty Commit in Git

Short answer

An empty commit contains no file changes and is created with git commit --allow-empty -m "Your message" — without the --allow-empty flag, Git would reject a commit with nothing staged. The most common use case is manually re-triggering a CI/CD pipeline: pushing an empty commit causes the remote to fire push-triggered events and re-run the workflow without any code change. Empty commits also appear in git log exactly like any other commit, which makes them useful for marking milestones, deployment events, or annotations in the project timeline. They are valid Git commits, can be pushed to a remote with git push, and can be reverted with git revert just like any other commit. Outside of CI triggering and historical bookmarks, empty commits have limited everyday utility and should be used sparingly to avoid cluttering the project history.

Creating an empty commit in Git is a very simple process. All you need to do is add the --allow-empty flag to the git commit command. This option lets Git know that you are intentionally creating a commit without any changes.

In the terminal, this is what you will need to type:

git commit --allow-empty -m "Your commit message"

If you run git log afterwards, you will see the newly added commit, which will look like any other regular commit! ✌️

As usual, you can then push it to your remote repository by using the git push command, like in the following example:

git push origin main

That's it!

No Command Line Needed

Empty Commits in Tower

If you are using the Tower Git client, empty commits will be shown, just like any other commit. The difference is that they won't contain any changes, of course!

Tower — Empty Commit

During merge or rebase operations, if you end up in a scenario where no files were changed and there are no changes to commit, Tower will also allow you to create empty commits.

Why Create Empty Commits?

You might be curious about why someone would want to create an empty commit in Git. After all, aren't commits typically used to keep track of changes to files in a project?

While we recommend that you use them with caution, as they can make the commit history more cluttered, there are actually a few scenarios where this might make sense:

  1. Triggering CI/CD Pipelines: This is the most common use case for empty commits. Sometimes, you may want to trigger a CI/CD pipeline without actually making any changes to the codebase. Creating an empty commit can be a way to do this, as the pipeline will still be triggered by the new commit.
  2. Workarounds for Git Hooks: Similar to what we mentioned above, there are situations where Git hooks may need a commit to exist before they can run. You can resolve this by creating an empty commit, which will satisfy this requirement.
  3. Marking Milestones: Empty commits can be used to mark important milestones or events in a project's history, without actually changing any code. This can help provide context in the commit history.
  4. Merging Branches: When merging two branches, an empty commit can be created to represent the merge, even if there were no actual conflicts or changes to resolve. This can make the commit history clearer.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!