Git FAQ
Frequently asked questions around Git and Version Control.
Git FAQ featured image

How to Create and Push an Empty Commit in Git

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!

Tip

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!


Learn More

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.