λ!

A blog about all things code

Stash Pull Pop

If you happen to work on the same branch with multiple people, it can be cumbersome to pull from upstream if you have unstaged changes.

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

For this I use a shell script that does the following:

The script (e.g. ~/scripts/spp.sh):

#!/bin/bash

# This script will stash local changes before pulling, if there
# are any.
if [[ `git status --porcelain --untracked-files=no` ]]; then
  git stash && git pull --rebase && git stash pop
else
  git pull --rebase
fi

Combined with an alias:

# ~/.bash_aliases
alias spp="~/scripts/spp.sh"

Tags: Git