The letter A styled as Alchemists logo. lchemists
Published August 15, 2020 Updated August 15, 2020

Git Commit Empty

Demonstrates using empty Git commits for an effective workflow.

Transcript

# Hello and welcome to the Alchemists Screencasts!
# Today, we'll learn about empty Git commits.

# Sometimes, when working in a feature branch, it's handy to section commits by group.
# For instance, here's our current log:

gl

# 💡 See *Git Log Pretty* screencast for `gl` alias details.

# While work is complete, it would be nice to stay working in this branch.
# In that case, a single branch of sectioned work is a good approach.
# Here's how I use empty commits to section off work:

git commit --allow-empty --no-verify --message "----- End of Implementation -----"
gl

# The `--allow-empty` option makes empty commit creation possible.
# The `--no-verify` option bypasses Git Hooks since empty commits should be discouraged.
# The five dashes (-) on each side of the message provides a clear visual in the logs.

# Again, an empty commit, is just a commit message only:

git show

# At this point, we can proceed with work in the branch.
# I'll speed up this demonstration by taking a few shortcuts so bare with me:

touch CHANGES.adoc
git add CHANGES.adoc
git commit --message "Added changes documentation"
touch CODE_OF_CONDUCT.adoc
git add CODE_OF_CONDUCT.adoc
git commit --message "Added code of conduct documentation"
git commit --allow-empty --no-verify --message "----- End of Documentation -----"
gl

# Ignoring implementation details and lack of commit messages, notice the sectioned log.
# Notice how each group of commits is a section of related work.

# At this point you might be wondering why is this important?
# Well, the above allows you to create branches, dynamically, per section for code review.
# This saves you time from creating and managing chained branches as an upfront cost.
# Plus, you can work with the *full* implementation unencumbered in a single branch.

# As you rebase, the editor will visually mark the empty commits for you too:

git rebase --interactive

gl

# Over time your team will provide code review feedback.
# Once each section is approved, you can rebase to have sections disappear.

# ⚠️  Don't allow empty commits on `master`.
# ⚠️  This technique is *only* useful for feature branches.

# Hopefully this provides you with a workflow that is easier to maintain.

# Enjoy!
# https://alchemists.io
# ☿ 🜔 🜍 🜂 🜃 🜁 🜄