Skip to content

Instantly share code, notes, and snippets.

@andypotanin
Created October 21, 2016 07:06
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 andypotanin/25122962a6ac9689176329fdf1b66ccf to your computer and use it in GitHub Desktop.
Save andypotanin/25122962a6ac9689176329fdf1b66ccf to your computer and use it in GitHub Desktop.
Put into a directory that is in $PATH. Then run "git deploy {branch}" to push current branch into it.
#!/usr/bin/env bash
## Deploy branch into "develop" branch
##
## Usage:
##
## git deploy production
##
## Save Original Branch
ORIGINAL_BRANCH=$(git symbolic-ref --short HEAD)
PARENT_TARGET=$(git show-branch -a | awk -F'[]^~[]' '/\*/ && !/'"$ORIGINAL_BRANCH"'/ {print $2;exit}');
if [ -n "${1}" ]; then
PARENT_BRANCH=${1};
else
PARENT_BRANCH=${PARENT_TARGET/origin\//}
fi
echo "Deploying [${ORIGINAL_BRANCH}] into [${PARENT_BRANCH}]."
## Checkout target branch "develop"
git checkout ${PARENT_BRANCH}
## Pull down develop branch
git pull
## Merge our original branch into the develop branch
git merge origin/$ORIGINAL_BRANCH -m "Deploying [${ORIGINAL_BRANCH}] into [${PARENT_BRANCH}]."
## Push to develop
git push
## Checkout our original branch again
git checkout ${ORIGINAL_BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment