Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@randomecho
Last active December 1, 2017 16:54
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 randomecho/59873654428bc4e07566e913b59ea058 to your computer and use it in GitHub Desktop.
Save randomecho/59873654428bc4e07566e913b59ea058 to your computer and use it in GitHub Desktop.
Merge and then delete traces of feature branch
#!/bin/sh
feature_branch=$(git branch | grep \* | sed 's/\* //')
all_branches=$(git branch | tr '\n' ' ')
main_branch=$1
if [[ $all_branches != *$main_branch* ]]; then
echo "$main_branch is not a valid branch to merge back into"
exit 1
fi
exit
if [ $# -ne 1 ]; then
echo "missing main branch to merge back into"
exit 1
fi
if [ $feature_branch == $main_branch ]; then
echo "cannot merge branch into itself"
exit 1
fi
git checkout $main_branch
git pull
git merge $feature_branch
git push origin $main_branch
git push origin --delete $feature_branch
git branch -D $feature_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment