Skip to content

Instantly share code, notes, and snippets.

@Sy1v4in
Created October 9, 2018 07:53
Show Gist options
  • Save Sy1v4in/d55003d2eed567844515595aeb0a0152 to your computer and use it in GitHub Desktop.
Save Sy1v4in/d55003d2eed567844515595aeb0a0152 to your computer and use it in GitHub Desktop.
#!/bin/bash
stash() {
# check if we have uncommited changes to stash
git status --porcelain | grep "^." >/dev/null;
if [ $? -eq 0 ]
then
if git stash save -u "git-update on `date`";
then
stash=1;
fi
fi
}
unstash() {
# check if we have uncommited change to restore from the stash
if [ $stash -eq 1 ]
then
git stash pop;
fi
}
stash=0;
stash;
branch=`git branch | grep "\*" | cut -d " " -f 2-9`;
if [ "$branch" == "master" ]
then
git pull origin master;
else
git checkout master;
git pull origin master;
git checkout "$branch";
git rebase master;
fi
unstash;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment