Skip to content

Instantly share code, notes, and snippets.

@swcho
Created November 9, 2016 04:51
Show Gist options
  • Save swcho/6e0d9038bbe9ea754487a23540411e21 to your computer and use it in GitHub Desktop.
Save swcho/6e0d9038bbe9ea754487a23540411e21 to your computer and use it in GitHub Desktop.
Distribute To Branch
#!/bin/bash
set -e
GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
if [ "$GIT_REPO_ROOT" != "$PWD" ]; then
echo "Should run this script in the repository root";
exit 1;
fi
GIT_BRANCH_NAME=$(git symbolic-ref HEAD 2>/dev/null)
if [ "$GIT_BRANCH_NAME" != "refs/heads/master" ]; then
echo "Should checkout master branch";
exit 1;
fi
if [[ -n $(git status -s) ]]; then
echo "Should be clean";
exit 1;
fi
if [[ -n $(git log origin/master..master) ]]; then
echo "Should be pushed to master";
exit 1;
fi
# Update remote commits
git remote update
# Get hash
LAST_HASH=$(git rev-parse HEAD)
echo "Commit $LAST_HASH will be distributed"
# Check out to dist branch
git checkout dist
# Rebase against master
git rebase master
# Reset to last commit
git reset --hard $LAST_HASH
# Build
npm run build
# Add built files
git add dist-prd
# Commit
git commit -am "Built"
# Push
git push -f
# Back to master
git checkout master
echo "FINISHED"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment