Last active
November 19, 2025 16:20
-
-
Save eerison/067a40def7492bd3268591dd4de2faba to your computer and use it in GitHub Desktop.
Bash script to update frontend theme
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
| #!/bin/bash | |
| UPSTREAM_TAG=$1 | |
| RESET_BRANCHES=${2:-"1"} | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| # Delete branches created. | |
| if [[ "$RESET_BRANCHES" == "1" ]]; then | |
| git branch -D "$CURRENT_BRANCH-preview" upstream | |
| fi | |
| echo "Upstream branch/tag selected: \"$UPSTREAM_TAG\"" | |
| echo "Current branch: \"$CURRENT_BRANCH\"" | |
| git checkout -b "$CURRENT_BRANCH-preview" | |
| # It will take the base commit, it is the squash commit from upstream. | |
| BASE_COMMIT=$(git rev-list --reverse HEAD | sed -n 1p) | |
| # SECOND_COMMIT=$(git rev-list --reverse HEAD | sed -n 2p) | |
| echo "Base commit \"$BASE_COMMIT\"" | |
| git log $BASE_COMMIT | |
| git fetch upstream $UPSTREAM_TAG:upstream | |
| git checkout upstream | |
| #Squash all commits from upstream | |
| git reset --soft $(git rev-list --max-parents=0 HEAD) && git commit --amend -m "Initial commit from upstream ($UPSTREAM_TAG)" --no-edit | |
| BASE_PREVIEW_COMMIT=$(git rev-list --reverse HEAD | sed -n 1p) | |
| git checkout "$CURRENT_BRANCH-preview" | |
| #Take all commits after base commit in main branch and put o top of preview. | |
| #In other words take all your changes. | |
| git rebase --onto $BASE_PREVIEW_COMMIT $BASE_COMMIT $CURRENT_BRANCH-preview | |
| cat << EOF | |
| Check the "$CURRENT_BRANCH-preview" branch and in case there are conflicts solve them. | |
| TIP: In case you have changes in files that you deleted like upstream blog's post, you can just remove ignore them. e.g: | |
| git rm -r src/data/blog | |
| After solve all conflicts finish the rebase. | |
| git rebase --continue | |
| If everything looks fine, then update your main branch and push your changes running commands bellow. | |
| git checkout $CURRENT_BRANCH | |
| git reset --hard $CURRENT_BRANCH-preview | |
| git push -f | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment