Last active
November 9, 2021 00:15
-
-
Save ChristopherA/f2f093ddd1da685f8f2e5f452c3a859d to your computer and use it in GitHub Desktop.
Git "Prepare Before" Snippet
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # inspired by https://github.com/heroku/cli/blob/master/scripts/publish-release | |
| CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
| MAIN_BRANCH="master" | |
| if [[ "${CURRENT_BRANCH}" != "${MAIN_BRANCH}" ]]; then | |
| echo "This script must be run on the ${MAIN_BRANCH}." | |
| echo "Please checkout the ${MAIN_BRANCH} branch with:" | |
| echo "git checkout ${MAIN_BRANCH}" | |
| exit 1 | |
| fi | |
| if ! (command -v gh > /dev/null); then | |
| echo "GitHub CLI is required for this release script." | |
| echo "Please install GitHub CLI and try again:" | |
| echo "https://github.com/cli/cli#installation" | |
| exit 1 | |
| fi | |
| # hostname is necessary just in case you are logged into the CLI | |
| # GitHub enterprise instance | |
| if ! (gh auth status --hostname "github.com" > /dev/null 2>&1); then | |
| echo "Not logged into github". | |
| echo "Please run: gh auth login" | |
| exit 1 | |
| fi | |
| git pull --rebase origin "${MAIN_BRANCH}" | |
| # The --force overrides local tags. | |
| # This is needed if you've published previously, | |
| # otherwise git will exit with an error unnecessarily. | |
| git fetch origin --force --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment