Last active
May 29, 2020 07:32
-
-
Save anowell/6869400 to your computer and use it in GitHub Desktop.
A git script to accommodate my workflow of merging (or rebasing) a particular feature branch into master: pull master, optionally rebase the feature branch, merge back to master, push, and finally remove branch.
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/sh | |
# | |
# My workflow: | |
# git checkout -b myfeature | |
# ...edit stuff...git commit...edit stuff...git commit...ready to ship... | |
# git ship myfeature -rpd | |
# | |
# It exits if the merge or rebase requires intervention, | |
# for merge: fix the conflict, commit the merge, and re-run the git ship command | |
# for rebase: clean up the conflict, run `git rebase --continue` and then re-run the git ship command | |
# I'm still debating the value of implementing the --continue (or --abort) in this command | |
set -e | |
REBASE=false | |
PUSH=false | |
DELETE=false | |
GETOPT=getopt | |
# Mac users: "homebrew install gnu-getopt" and use the full path to the getopt keg | |
# GETOPT="/usr/local/Cellar/gnu-getopt/1.1.4/bin/getopt" | |
# Execute getopt | |
ARGS=`$GETOPT -o "rpd" -l "rebase,push,delete,continue,abort" \ | |
-n "getopt.sh" -- "$@"` | |
#Bad arguments | |
if [ $? -ne 0 ]; | |
then | |
exit 1 | |
fi | |
# A little magic | |
eval set -- "$ARGS" | |
# Now go through all the options | |
while true; | |
do | |
case "$1" in | |
-r|--rebase) | |
echo "--rebase" | |
REBASE=true | |
shift;; | |
-p|--push) | |
echo "--push" | |
PUSH=true | |
shift;; | |
-d|--delete) | |
echo "--delete" | |
DELETE=true | |
shift;; | |
--abort) | |
echo "FYI: --abort is not yet implemented" | |
ABORT=true | |
shift;; | |
--continue) | |
echo "FYI: --continue is not yet implemented" | |
CONTINUE==true | |
shift;; | |
--) | |
shift | |
break;; | |
esac | |
done | |
BRANCH=$1 | |
# User is not in git repository | |
if ! git branch > /dev/null 2>&1 ; then | |
echo "'$(basename ${PWD})' - Not a Git repository." | |
exit 1 | |
elif [ -z "$BRANCH" ]; then | |
echo "USAGE: git ship <BRANCH>" | |
exit 1 | |
fi | |
git checkout master | |
git pull --rebase | |
if $REBASE ; then | |
git rebase master $BRANCH | |
git checkout master | |
fi | |
git merge $BRANCH | |
MSG="" | |
if $PUSH ; then | |
git push | |
MSG="${MSG}Pushed successfully! " | |
fi | |
if $DELETE ; then | |
git branch -d $BRANCH | |
MSG="${MSG}Removed branch '${BRANCH}' " | |
fi | |
echo "git ship succeeded: $MSG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment