git pull --autostash

I’ve recently moved from a largely merge commit based git workflow to a squash and merge based one. Learning to flex my git rebase muscles has been refreshing, and I’m enjoying the cleaner git log that results.

As part of the workflow, I’ve changed my git pull to default to rebasing on pull, rather than merging (the default). The only thing that’s rough about this workflow is whenever I have local changes, git pull will fail, telling me that I have unstaged changes:

▵ git pull
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

To work around this, I’d typically do a compound shell command (I’m using fish - you would typically do this with && in bash):

▵ git stash; and git pull; and git stash pop

I recently discovered the solution to needing this: git pull --autostash! It automatically stashes your current working directory and re-applies it after the pull.

▵ git pull --autostash
Created autostash: a14af18
Current branch master is up to date.
Applied autostash.

This option is so handy for my workflow that I made an alias for it.

🥳