Syndication Icon
Published October 29, 2019 Updated May 15, 2020

Git Rebase AutoStash

  • Duration

    01:55

  • Operating System

    macOS

  • Shell

    bash

  • Terminal

    xterm

Transcript

# Hello and welcome to the Alchemists Screencasts!
# Today, we'll learn to configure Git Rebase AutoStash support.
# For context, I've started working on a new project:

gl

# I've also started developing a simple multiplication script:

git status --short --branch

# At this point, it'd be nice to rebase to clean up that *fixup!* commit.
# Since this project hasn't been shared yet:

git remote --verbose

# ...I'll rebase from root:

git rebase --interactive --root

# Notice that last error: "Please commit or stash them."
# Git wants me to stash my changes before preceding.
# OK, I'll comply:

git stash push --message "Work Prior to Rebase"

# Let's see if I can rebase now:

git rebase --interactive --root

# Let's pretend I didn't abort the rebase and wanted to continue working.
# I then have to remember to pop my stash before returning to work:

git stash pop
git status --short --branch

# That's a lot of work (pushing and popping the stash). 😅
# All of that is necessary in order to rebase and continue working.
# Thankfully, Git can automate this for us via AutoStash. 🎉

git config --add rebase.autoStash true

# With that configuration in place, let's rebase again.

git rebase --interactive --root

# Notice, prior to the rebase, Git auto-stashed our changes:
#
# "Created autostash"
#
# Then, after completing the rebase, Git auto-popped the stash:
#
# "Applied autostash."
#
# We can also see the rebase cleaned up our history:

gl

# ...and our staged file is back where we left it:

git status --short --branch

# If you don't have this enabled as part of your workflow, I recommend adding it.
# In fact, this setting is so handy, configuring it globally yields maximum benefit:
#
# git config --global --add rebase.autoStash true

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