Skip to content

Instantly share code, notes, and snippets.

@mirshko
Created January 9, 2018 09:51
Show Gist options
  • Save mirshko/01874db297e6c82dba607c009c89acb6 to your computer and use it in GitHub Desktop.
Save mirshko/01874db297e6c82dba607c009c89acb6 to your computer and use it in GitHub Desktop.
Bash script to update a git branch from master and then push it back to GitHub.
rebaseAndPush() {
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
echo "\nWorking branch: $BRANCH"
echo "\nRebase branch?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "\nUpdating $BRANCH from master" && git fetch origin && git rebase origin/master; break;;
No ) break;;
esac
done
echo "\nPush to Github?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "\nPushing branch: $BRANCH to Github" && git push -f origin $BRANCH:$BRANCH; break;;
No ) break;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment