Skip to content

Instantly share code, notes, and snippets.

@jancimajek
Last active October 11, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jancimajek/c744675a13da3357a7e9d3959b6b1d3b to your computer and use it in GitHub Desktop.
Save jancimajek/c744675a13da3357a7e9d3959b6b1d3b to your computer and use it in GitHub Desktop.
Smart rebase master
#!/bin/bash
# GITS: https://gist.github.com/jancimajek/c744675a13da3357a7e9d3959b6b1d3b
echo "[git fetch]"
git fetch
NEEDS_UPDATE=$(git log HEAD..origin/master --oneline | wc -l)
if [ $NEEDS_UPDATE -eq 0 ]
then
echo "Master already up to date, no need to update"
exit 0
fi
GITWB=$(git rev-parse --abbrev-ref HEAD)
GITTS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
STASH_MSG="YNCX WIP at ${GITTS}"
echo && echo "[git stash]"
git stash push -m "${STASH_MSG}"
echo && echo "[git checkout master]"
HUSKY_SKIP_HOOKS=1 git checkout master
echo && echo "[git pull -r]"
HUSKY_SKIP_HOOKS=1 git pull -r
echo && echo "[git checkout ${GITWB}]"
HUSKY_SKIP_HOOKS=1 git checkout "$GITWB"
echo && echo "[git rebase master]"
HUSKY_SKIP_HOOKS=1 git rebase master
git stash list | grep "^stash@{0}: On ${GITWB}: ${STASH_MSG}$" && echo && echo "[git stash pop]" && git stash pop
echo && echo '[yarn install --frozen-lockfile]'
cd ~/Projects/red-badger/one-pay-fx
yarn install --frozen-lockfile
echo && echo '[yarn clean build]'
cd ~/Projects/red-badger/one-pay-fx/shared
yarn clean
yarn compile
cd ~/Projects/red-badger/one-pay-fx/api
yarn clean
yarn compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment