Last active
March 23, 2016 14:06
-
-
Save mzahor/abff01eb9bbaab818fbb to your computer and use it in GitHub Desktop.
Branch squasher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
current_br=$(git name-rev --name-only HEAD) | |
tmp_br=${current_br}_temp | |
# remove temp branch if already exists | |
if [[ $(git br | grep ${tmp_br}) != '' ]]; then | |
git br -D ${tmp_br} | |
fi | |
if [[ "${current_br}" == "release" ]]; then | |
echo "Warning: do you really want to squash ${current_br}?" | |
else | |
echo "Squashing branch ${current_br}. Confirm by entering \"y\"" | |
fi | |
# confirmation | |
read -r | |
if [[ "$REPLY" != "y" ]]; then | |
exit 1 | |
fi | |
git co release | |
# git pull | |
git co -b ${tmp_br} | |
git merge --squash ${current_br} | |
# if you need to abort the scipt at this point | |
# enter :cq in vim to exit with an error code | |
git ci | |
git br -D ${current_br} | |
git co -b ${current_br} | |
git br --set-upstream-to origin/${current_br} ${current_br} | |
echo 'Now you can push -f' | |
echo 'Success!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment