Skip to content

Instantly share code, notes, and snippets.

@adarshaacharya
Forked from darronz/rebase.sh
Created October 20, 2022 02:18
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 adarshaacharya/615f2e6620023e8502047d944dad7225 to your computer and use it in GitHub Desktop.
Save adarshaacharya/615f2e6620023e8502047d944dad7225 to your computer and use it in GitHub Desktop.
Bash script to rebase your current branch on master
#!/bin/bash
# store name of current branch
BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
# checkout master
git checkout master
# pull the latest changes
git pull
# fetch and prune all the branches
git fetch --all --prune
# checkout the original branch
git checkout $BRANCH
# rebase on master
git rebase master
# prompt to push the changes
read -p "Would you like to push the changes? [y/n] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
git push --force --no-verify
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment